我想知道如何在C ++中构建$ in查询。我能够成功构建这样的$ nin查询:
mongo::BSONArrayBuilder bab;
bab << "category1";
bab << "category2";
mongo::BSONObjBuilder bobQuery;
bobQuery << "category" << mongo::NIN << bab.arr();
但是,似乎没有相应的mongo :: IN来构建相应的$ in查询。至少,我找不到一个挖掘源头。
答案 0 :(得分:0)
您可以这样做:
mongo::BSONObjBuilder bobQuery;
bobQuery << "category" << BSON( "$in" << bab.arr());
或
mongo::BSONObjBuilder bobQuery;
mongo::BSONObjBuilder catQuery;
bobQuery.append("$in", bab.arr());
catQuery.append("category", bobQuery.done());