I have a long string in JSON format, and I want to convert it into a BSONDocument for insertion into a MongoDB database. How do I do the conversion? I'm using the official C# driver.
The answer is:
string json = "{ 'foo' : 'bar' }"; MongoDB.Bson.BsonDocument document     = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(json); 
                        string json = "{ 'foo' : 'bar' }";   BsonDocument document = BsonDocument.Parse(json); 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With