Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string into MongoDB BsonDocument

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.

like image 365
Journeyman Avatar asked Apr 11 '11 17:04

Journeyman


Video Answer


2 Answers

The answer is:

string json = "{ 'foo' : 'bar' }"; MongoDB.Bson.BsonDocument document     = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(json); 
like image 168
Journeyman Avatar answered Sep 30 '22 07:09

Journeyman


string json = "{ 'foo' : 'bar' }";   BsonDocument document = BsonDocument.Parse(json); 
like image 44
m_hawk13 Avatar answered Sep 30 '22 07:09

m_hawk13