Skip to content

Instantly share code, notes, and snippets.

@Sandiejat
Last active May 16, 2020 22:57
Show Gist options
  • Select an option

  • Save Sandiejat/b7accbe2d894bb00393d961708122036 to your computer and use it in GitHub Desktop.

Select an option

Save Sandiejat/b7accbe2d894bb00393d961708122036 to your computer and use it in GitHub Desktop.
Example to convert a BsonDocument to DotNet Object using MongoDB.Bson in C#
var bsonDoc = new BsonDocument
{
{"title", "My Title"},
{"datetime", DateTime.UtcNow},
{"number", 100},
{"some_decimal", 50.0}
};
var dotNetObj = BsonTypeMapper.MapToDotNetValue(bsonDoc);
JsonConvert.SerializeObject(dotNetObj);
var bsonDocList = new List<BsonDocument>();
var dotNetObjList = bsonDocList.ConvertAll(BsonTypeMapper.MapToDotNetValue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment