title: How can I delete nested array element in a mongodb document with the c# driver
body: <p>I am new in the MongoDB world and now I am struggling of how can I delete, update element in a nested array field of a document. Here is my sample document:</p>
  
  <pre><code>{
      "_id" : ObjectId("55f354533dd61e5004ca5208"),
      "Name" : "Hand made products for real!",
      "Description" : "Products all made by hand",
      "Products" : [ 
          {
              "Identifier" : "170220151653",
              "Price" : 20.5,
              "Name" : "Leather bracelet",
              "Description" : "The bracelet was made by hand",
              "ImageUrl" : "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQii6JCvXtx0iJGWgpvSl-KrdZONKYzDwS0U8uDvUunjO6BO9Aj"
          }
      ]
  } 
  </code></pre>
  
  <p>In my method, I get the id of the document and the id(Identifier) of the Product that I want to delete. Can anyone tell me how can I delete from the Products field the element having Identifier: 170220151653?</p>
  
  <p>I tried:</p>
  
  <pre><code>var query = Query.And(Query.EQ("_id", categoryId), Query.EQ("Products.Identifier", productId));
  var update = Update.Pull("Products", new BsonDocument() { { "Identifier", productId } });
  myDb.Applications().Update(query, update);
  </code></pre>
  
  <p>as suggested here: <a href="https://stackoverflow.com/questions/6584037/mongodb-remove-a-subdocument-document-from-a-subdocument">MongoDB remove a subdocument document from a subdocument</a></p>
  
  <p>But I get an error at </p>
  
  <blockquote>
    <p>myDb.Applications()</p>
  </blockquote>
  
  <p>It just can't be found. </p>
  
  <p><strong>SOLVED:</strong></p>
  
  <pre><code>var pull = Update&lt;Category&gt;.Pull(x =&gt; x.Products, builder =&gt; builder.EQ(q =&gt; q.Identifier, productId));
  collection.Update(Query.And(Query.EQ("_id", ObjectId.Parse(categoryId)), Query.EQ("Products.Identifier", productId)), pull);
  </code></pre>