繁体   English   中英

如何在mongocxx(c ++)中抑制字段?

[英]how to Suppress Field in mongocxx (c++)?

我想知道mongocxx驱动程序(c ++)中的以下代码等效吗?

db.RadarPointsExl.find(
   { age: { $gt: 25, $lte: 50 },
{name:1 }
)

我的同事找到了答案,您可以使用以下代码:

using bsoncxx::builder::stream::document;
    mongocxx::options::find opts;
    document condition, options;
    mongocxx::instance instance{};
    mongocxx::client client{ mongocxx::uri{} };
    mongocxx::database db = client["RadarDB"];
    mongocxx::collection collection = db["RadarPointsExl"];

    condition << "age" << open_document << "$gt" << 25 << "$lte" << 50 << close_document;
    options << "name" << 1;
    opts.projection(options.view());
    mongocxx::cursor cursor = collection.find(condition.view(), opts);


    for (auto doc : cursor) {
        std::cout << doc["name"].get_utf8().value << "\n";

    }

我希望它是有用的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM