title: How can you add a nested element or update a property using mongo db C# driver with one call
body: <p>I am trying to have one db call to either add an element to a nested array or if that element already exists increase a counter on it. In this case we are trying to see if there is a matching SubDocument, if none is found we want to add that sub document to the SubDocs list if one is found we want to increment the Count prop on the SubDocument found in that list. </p>
  
  <p>The reason we are looking for one call to do this is because we will have several services potentially trying to do the same thing at the same time.</p>
  
  <pre><code>    public class Document
      {
          [BsonId]
          [BsonIgnoreIfDefault]
          [BsonRepresentation(BsonType.ObjectId)]
          public string DocumentID { get; set; }
  
          public int Date { get; set; }
          public List&lt;SubDocument&gt; SubDocs { get; set; }
      }
  
      public class SubDocument
      {
          public string Count { get; set; }
          public string Name { get; set; }
      }
  </code></pre>
  
  <p>Any help would be greatly appreciated. We are using the .NET driver 2.8.1</p>
  
  <p>I was able to do this using a find, and if its found update the counter. But testing so far shows counts will get missed if multiple services are doing this.</p>