编辑-在此为感兴趣的参与者提供了一些帮助> https://developer.mongodb.com/community/forums/t/writting-query-for-array-in-c/7793/2
我正在学习如何在mongo中操作数组/对象...目前正在尝试按照本教程>
https://blog.mlab.com/2018/09/use-push-to-insert-elements-into-an-array/
主要>
> db.alphabet.insert({
"_id": "22222",
"array": ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j']
})
// We missed the 'i'!
// Let's add it in the position before the last element.
> db.alphabet.update(
{ "_id": "22222" },
{
$push: {
array: {
$each: ['i'],
$position: -1
}
}
})
// Check the results:
> db.alphabet.find({ "_id": "22222" })
{ "array" : [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" ] }v
我从这样的东西开始>
auto replace = coll.update_one(make_document(kvp("_id", bsoncxx::oid("5f3289b7807200001f002b35"))),
make_document(kvp("$push", make_document(
kvp("arrayKeyTest","????????????????")
))));
但是卡住了其余的查询,数组...
我还想用类似以下的方法替换整个数组:
QVector<std::string> items= {"vfdsvds","vdsvsd","htrhjfgr","G243TYES"}
auto ar = bsoncxx::builder::basic::array{};
for(auto&e:items){
ar.append(e.c_str());
}
然后将ar作为某些键的值推入文档中...但是我迷路了...
任何帮助都会很棒。 TIA