title: Remove document from array in MongoDB Java
body: <p>I got a JSON string that looks something like this:</p>
  
  <pre><code>String tmp = "[
     {
        "ID":"12",
        "Date":"2018-02-02",
        "ObjData":[
           {
              "Name":"AAA",
              "Order":"12345",
              "Extra1":{
                 "Temp":"3"
              },
              "Extra2":{
                 "Temp":"5"
              }
           },
           {
              "Name":"BBB",
              "Order":"54321",
              "Extra1":{
                 "Temp":"3"
              },
              "Extra2":{
                 "Temp":"5"
              }
           }
        ]
     }
  ]"
  </code></pre>
  
  <p>I would like to remove for example the the document where ´Order´ equals "54321" from ´ObjData´. I got the following code:</p>
  
  <pre><code>Document doc = new Document();
  doc = Document.parse(tmp);
  
  Document fields = new Document("ID", "12")
      .append("ObjData", Arrays.asList(new Document("Order", "54321")));
  
  Document update = new Document("$pull", fields);
  
  coll.updateOne(doc, update);
  </code></pre>
  
  <p>I am trying to use the ´pull´ method to remove the entire document from the array where the ´Order´ equals 54321 but for some reason it's not working, I am probably doing something wrong. Could someone point out the issue please?</p>
  
  <p>Also, what would be the best way to keep count of the documents within the array so that once all documents are pulled the entire document is deleted from the database? Would it be good to add some kind of ´size´ attribute and keep track of the size and decrease it after each pull?</p>