2017-09-26 147 views

回答

0

我的同事找到答案,你可以使用使用下面的代碼:

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"; 

    } 

我希望這是有益的。