title: Remove complete document or element from array based on condition
body: <p>My collection documents are:</p>
  
  <pre><code>    {
        "_id" : 1,
        "fruits" : [ {"name":"pears"},
                     {"name":"grapes"},
                    {"name":"bananas"} ],
      }
      {
        "_id" : 2,
        "fruits" : [ {"name":"bananas"} ],
      }
  </code></pre>
  
  <p>I need to remove the whole document when the fruits contains only "bananas" or only remove the fruit "bananas" when there are more than one fruit in the fruits array.</p>
  
  <p>My final collection after running the <strong>required query</strong> should be:</p>
  
  <pre><code>{
    "_id" : 1,
    "fruits" : [ {"name":"pears"},
                     {"name":"grapes"}],
  }
  </code></pre>
  
  <p>I am currently using two queries to get this done:</p>
  
  <pre><code>db.collection.remove({'fruits':{$size:1, $elemMatch:{'name': 'bananas'} }}) [this will remove the document when only one fruit present]
  </code></pre>
  
  <p>and</p>
  
  <pre><code>db.collection.update({},{$pull:{'fruits':{'name':'bananas'}}},{multi: true}) [this will remove the entry 'bananas' from the array]
  </code></pre>
  
  <p>Is there any way to combine these into <strong>one query</strong>?</p>
  
  <p><strong>EDIT: Final take</strong></p>
  
  <p>-- I guess there is no "one query" to perform the above tasks since the intents are very different of both the actions.</p>
  
  <p>-- The best that can be performed is: club the actions into a bulk_write query which saves on the network I/O(as suggested in the answer by Neil). This is believe is more beneficial when you have multiple such actions being fired. Also, bulk_write can provide the feature of locking in the sense that the "ordered" mode of the bulk_write makes the actions sequential, breaking and halting execution in case of error.</p>
  
  <p>Hence bulk_write is more beneficial when the actions performed need to be sequential. Somewhat like "chaining" in JS. There is also the option to perform un-ordered bulk_writes.</p>
  
  <p>Also, the actions specified in the bulk write, operate on the <code>collection level as individual actions.</code></p>