还有另一种从传统驱动程序创建bson对象的方法,mongodb看起来像:
{ name: "abc", vals: [0,1,2,3,...,n] }
来自 std :: vector of floats 的vals元素?
在文件中,BSONObjBuilder().append
这是唯一的方法吗?
答案 0 :(得分:0)
您也可以使用BSON()
宏:
BSONObj b = BSON("name" << "abc" << "vals" << ba);
其中ba
是1,2,...,N列表的BSONArray
。您可以使用BSONArrayBuilder
来组成该数组,或者,如果您知道列表的大小,则可以使用BSON_ARRAY()
宏:
BSONArray ba = BSON_ARRAY( 1 << 2 << 3 << .. N );