微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Mongocxx如何查询文件数组

如何解决Mongocxx如何查询文件数组

我想根据“ size”元素查询包含文档的数组。

{
"number": 0,"features": [{
    "size": 10,"angle": 0.13546741008758545,"response": 0,},{
    "size": 40,"angle": 0.3170666992664337,}]

}

我做了如下

 //Create the query filter
 auto filter = bsoncxx::builder::stream::document{}  << "features.size"<< bsoncxx::builder::stream::open_document 
             <<"$gt" << 0 
             <<"$lte" << 30
            << bsoncxx::builder::stream::close_document << bsoncxx::builder::stream::finalize;


    mongocxx::options::find opts;
    opts.projection(bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("features",1)));
    auto cursor = db["deneme"].find(filter.view(),opts);

    for (auto&& doc : cursor) {
        std::cout << bsoncxx::to_json(doc) << std::endl;
    }

但是它返回“功能”的所有元素。如何仅获取满足条件的元素。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。