title: Getting the size of an array within a condition without using $match
body: <p>I have a query that I need to write where I need to determine the number of elements in an array (which I know can be done through <code>$project</code> with <code>$size</code> and then <code>$match</code>) but then I need to be able to process the array items that meet this condition, and if they don't meet the condition, leave them. I don't want to exclude the items that don't meet the criteria through a <code>$match</code> </p>
  
  <p>Here is the standard approach to counting items in the array that <strong>cannot work for what I need</strong>:</p>
  
  <pre><code>db.collection.aggregate([
    { $project: { _id:1,  
                  themeArraySize: { $gt: [ {$size: "$themes" }, 1 ] } } },
    { $match: { themeArraySize : true }} ,
  ])
  </code></pre>
  
  <p>I need to wrap that in a condition, and not exclude anything through match</p>
  
  <p>The "logic" for what I want to achieve for my themes array is this:</p>
  
  <ol>
  <li>If the array has a length > 1 AND</li>
  <li>There is an array item with the value "[]" OR "NO THEMES SELECTED"</li>
  <li>THEN $PULL "[]" or "NO THEMES SELECTED" from the themes array</li>
  <li>ELSE return the <code>themes</code> array</li>
  </ol>
  
  <p>The part i'm struggling with is the how to process the true logic</p>
  
  <p>Putting it in a sentence:</p>
  
  <p><strong>"If there is a theme in the array that is '[]' and this is the only theme, leave it alone. But if '[]' is present, and there are other themes, remove '[]' from the array"</strong></p>
  
  <p>I've made a start:</p>
  
  <pre><code>{
              "＄project": {
                "conversationid": 1,
                "themes": {
                  "＄cond": [
                    {
                      "＄and": [
                        {
                          "＄or": [
                            {
                              "＄in": [
                                "[]",
                                "$themes"
                              ]
                            },
                            {
                              "＄in": [
                                "NO THEMES SELECTED",
                                "$themes"
                              ]
                            }
                          ]
                        },
                        {
                          "$themes": {
                            "＄gte": [
  ******I WANT TO SAY THAT THE THEMES ARRAY MUST BE &gt;1 IN SIZE HERE******
                            ]
                          }
                        }
                      ]
                    },
                    {
                      "＄pull": {
                        "$themes": {
                          "＄in": [
                            "NO THEMES SELECTED",
                            "[]"
                          ]
                        }
                      }
                    },
                    "$themes"
                  ]
                }
              }
            },
  </code></pre>
  
  <p>But I getting the sense that what I want to do isn't possible</p>
  
  <p>Thanks</p>