我使用MongoDB的C++驱动程序,并试图蒙戈::查询类,使用JSON作为查询字符串一起结合起来。结合蒙戈::查询在C++驱动
在我的例子我试图Q1,Q2,Q3合并。我可以将q3转换为mongo :: fromjson(q3);在尝试赶在最终结合之前捕获不想要的错误,但我不确定这是否是最好的方式来做到这一点。
到目前为止,我只尝试使用BSON_ARRAY到独立的部分结合起来,但是这仍然是不出来我想(understably虽然)的方式。
///The output im trying to achieve is:
// {a : 1,b : 2, c : 3}
const mongo::Query q1 = QUERY("a" << 1);
const mongo::Query q2 = QUERY("b" << 2);
const std::string q3 = "{c : 3}";
// Attempt 1. I know it does not work.
mongo::Query qAll = BSON_ARRAY(q1.toString() << q2.toString());
std::cout << q1.toString() << std::endl;
// Outputs { a: 1 } as expected
std::cout << q2.toString() << std::endl;
// Outputs { b: 2 } as expected
std::cout << qAll.toString() << std::endl;
// Outputs { 0: "{ a: 1 }", 1: "{ b: 2 }" }, expected but wrong.
好,它的一点清洁感谢。 –