Last active
May 16, 2020 22:57
-
-
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#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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