【问题标题】:how to Suppress Field in mongocxx (c++)?如何在mongocxx(c ++)中抑制字段?
【发布时间】:2017-09-26 08:58:34
【问题描述】:

我想知道以下代码在 mongocxx 驱动程序 (c++) 中的等价物是什么?

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

【问题讨论】:

    标签: c++ mongodb nosql mongodb-query mongo-cxx-driver


    【解决方案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";
    
        }
    

    希望对你有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多