在mongodb C ++驱动程序中清空JSON ARRAY()

时间:2015-02-18 19:22:02

标签: c++ mongodb

以下适用于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宏生成空数组的提示吗?

1 个答案:

答案 0 :(得分:0)

似乎BSONArray()解决了这个问题:

  BSONObj cr4 = BSON("providingApplication" << "http://cpr2.com" <<
                     "entities" << BSON_ARRAY(
                         BSON("id" << "E1" << "type" << "T")
                         ) <<
                     "attrs" << BSONArray()
                     );

感谢ÖöTiib的小费!