When fetching information from MongoDB and sending it to the client, I encountered a dilemma:
var retrievedBsonDocument = ... retrieve data from database ...
var dtoObject = new Dto { MyBson = retrievedBsonDocument.ToJson() };
While trying to parse the MyBson
property on the client side using JSON.parse
, I encountered an error message: SyntaxError: Unexpected token N
. This seems to be due to one of the properties being structured like this:
{ ..., "SomeIntProp" : NumberLong(70) }
The JavaScript parser is unable to interpret the Bson data type known as NumberLong
.
What would be the best way to convert the BsonDocument to JSON in order to exclude occurrences of NumberLong
?