title: How to convert UpdateResult from MongoDB C# Driver to JSON
body: <p>Providing some contextual information: I want to integrate some technology with MongoDB using the official C# driver, but due some limitations I need to integrate it using only JSON strings. So, I'm building a simple wrapper to the native functions to call they by passing and receiving JSON as simple strings.</p>
  
  <p>Example of the <code>find</code> method:</p>
  
  <pre><code>public string find(string json)
  {
      BsonDocument query = BsonDocument.Parse(json);
      var list = Collection.Find(query).ToListAsync().Result;
      return list.ToJson();
  }
  </code></pre>
  
  <p>P.S.: I know the performance implications of using an async method as a synchronous one, but I have no choice.</p>
  
  <p>This works pretty well, the problem is with the update/replace method:</p>
  
  <pre><code>public string updateMany(string jsonFilter, string jsonUpdate)
  {
      BsonDocument filter = BsonDocument.Parse(jsonFilter);
      BsonDocument update = BsonDocument.Parse(jsonUpdate);
      UpdateResult r = Collection.UpdateManyAsync(filter, update).Result;
      return r.ToJson();
  }
  </code></pre>
  
  <p>This returns the string: <code>{ "_t" : "Acknowledged" }</code>, which only tells me the class of the <code>UpdateManyAsync()</code> result. That class expose some properties like <code>MatchedCount</code> and <code>ModifiedCount</code> that I would like to put on JSON too, but the default serializer is ignoring them by some reason (those properties are read-only, so should be ignored on deserializing, but not on serializing).</p>
  
  <p>I tried to use <code>r.ToJson&lt;UpdateResult&gt;();</code> and <code>r.ToBsonDocument&lt;UpdateResult&gt;();</code>, but got the same result.</p>
  
  <p>I saw that <code>toJson()</code> has some overloads receiving a <code>JsonWriterSettings</code>, an <code>IBsonSerializer</code> and a <code>BsonSerializationArgs</code>, so maybe one of them holds some configuration about the subject, but I have no luck searching for it.</p>
  
  <p>I think that I could import <a href="http://www.newtonsoft.com/json" rel="nofollow">Json.NET</a> DLL to see if it serializes all the properties, but I would like to solve it without another dependency.</p>