gpt4 book ai didi

c++ - 带有 MongoDB C++ 驱动程序的 BSON 文档中的 fin

转载 作者:行者123 更新时间:2023-11-28 01:56:34 25 4
gpt4 key购买 nike

我的 MongoDB 测试数据库中有以下文档:

    db.a.find()
{[ {
"_id" : ObjectId("5113d680732fb764c44qweq"),
"Builds" : [
{
"level" : 1,
"rank" : 2
},
{
"level" : 3,
"rank" : 4
}
]
}, {
"_id" : ObjectId("5113d680732fb764c4464fdf"),
"Builds" : [
{
"level" : 3,
"rank" : 5
},
{
"level" : 3,
"rank" : 4
}
]
}
]}

我需要找到 => 1 和 <= 2 的级别你能帮帮我吗?可以用 mongocxx 做吗?

最佳答案

mongocxx::cursor cursor = collection.find(
document{} << "Builds.level" << open_document <<
"$gte" << 1 <<
"$lte" << 2
<< close_document << finalize);

for(auto doc : cursor) {
std::cout << bsoncxx::to_json(doc) << "\n";
}

将获取的 mongo 原始查询如下:

db.a.find({"Builds.level":{$gte:1}, "Builds.level":{$lte:2}})

关于c++ - 带有 MongoDB C++ 驱动程序的 BSON 文档中的 fin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40995202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com