fgalan
fgalan

Reputation: 12322

MongoDB C++ driver BSON() usage to generate BSON with null values

Is there a way of using BSON() macro from the MongoDB C++ driver in order to generate a BSON will null value. For examples, in order to generate a BSON to represent this document: {"a": "foo", "b": null}:

BSONObj myObj = BSON("a" << "foo" << "b" << <something that I don't know>);

I have tried with this (naïve) approach but it doesn't work:

BSONObj myObj = BSON("a" << "foo" << "b" << NULL);

Upvotes: 2

Views: 389

Answers (1)

acm
acm

Reputation: 12727

I think you want to do:

BSONObj myObj = BSON("a" << "foo" << "b" << BSONNULL);

See this tutorial file for another example.

Upvotes: 2

Related Questions