0

Using the MongoDB C# driver, the following code gives me { } in the json variable. It seems to ignore the null value in its serialization.

var document = new BsonDocument{{"x", null}};
var json = document.ToJson();

However I want json to be { "x": null }. Can I set some option for it to serialize null values?

1
  • BsonDocument is what is ignoring the null, but AntonioOtero's answer is correct way to solve it Commented Jun 25, 2013 at 13:09

1 Answer 1

2

Somebody else asked something similar here

Basically, you have to use BsonNull.Value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.