I have a question that official examples couldn’t help me out
I am trying to update a array inside of a single document by c++ vector. Here is an example test document:
{
"_id" : "05469b3c-73ad-412e-9703-52567269e7aa",
"quality" : "2",
"author" : [
"Kawamura T",
"Imamura CK",
"Kenmotsu H",
"Taira T",
"Omori S",
"Nakashima K",
"Wakuda K",
"Ono A",
"Naito T",
"Murakami H",
"Mushiroda T",
"Takahashi T",
"Tanigawara Y"
]
}
and I have a new author list writing in vector that want to replace the “author” array in mongodb,what is the exact synatx to do that like
collection.update_one(make_document(kvp("_id", oid)),
make_document(kvp("$set", make_document(kvp("quality", 6))))
);
after searching maybe it will be like:
vector<string> new_author_list;
new_author_list.push_back("aaa");
new_author_list.push_back("bbb");
new_author_list.push_back("ccc");
for (int i = 0; i < new_author_list.size(); i++)
{
string& single_new_auther = new_author_list[i];
collection.update_one(make_document(kvp("_id", uuid)),
make_document(kvp("$set", make_document(
kvp("author." + i, single_new_auther)
)))
);
}
but I am not sure, because I can’t find any similar example in mongo-cxx-driver-rx.x.x/examples/mongocxx