2016-01-12 92 views
2

有沒有一種方法可以使用來自MongoDB C++驅動程序的BSON()宏來生成一個BSON爲空的值。有關示例,以產生一個BSON來表示此文件:{"a": "foo", "b": null}MongoDB C++驅動程序使用BSON()生成空值的BSON

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

我曾嘗試與此(天真)的方式,但它不工作:

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

回答

2

我想你想要做:

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

另一個例子見this tutorial file

+0

沒錯!謝謝! – fgalan