以下适用于mongo C ++ BSON()和BSON_ARRAY()宏:
BSONObj cr4 = BSON("providingApplication" << "http://cpr2.com" <<
"entities" << BSON_ARRAY(
BSON("id" << "E1" << "type" << "T")
) <<
"attrs" << BSON_ARRAY(
BSON("name" << "A5" << "type" << "T" << "isDomain" << "false")
)
);
但是,如果我尝试将空BSON数组用于attrs
字段
BSONObj cr4 = BSON("providingApplication" << "http://cpr2.com" <<
"entities" << BSON_ARRAY(
BSON("id" << "E1" << "type" << "T")
) <<
"attrs" << BSON_ARRAY()
);
它不起作用(它甚至不编译)。
有关如何使用mongo c ++驱动程序中的BSON宏生成空数组的提示吗?
答案 0 :(得分:0)
似乎BSONArray()
解决了这个问题:
BSONObj cr4 = BSON("providingApplication" << "http://cpr2.com" <<
"entities" << BSON_ARRAY(
BSON("id" << "E1" << "type" << "T")
) <<
"attrs" << BSONArray()
);
感谢ÖöTiib的小费!