gpt4 book ai didi

c++ - MongoDB C++ 驱动程序 BSON() 用于生成具有空值的 BSON

转载 作者:可可西里 更新时间:2023-11-01 10:25:08 28 4
gpt4 key购买 nike

有没有一种方法可以使用 MongoDB C++ 驱动程序中的 BSON() 宏来生成 BSON 将空值。例如,为了生成一个 BSON 来表示这个文档:{"a": "foo", "b": null}:

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

我尝试过这种(天真的)方法,但它不起作用:

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

最佳答案

我想你想做的是:

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

参见 this tutorial file再举个例子。

关于c++ - MongoDB C++ 驱动程序 BSON() 用于生成具有空值的 BSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34751520/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com