I want to update the "user"-array of the following JSON-document which is saved in a MongoDB Database (programming language C++)
{
"_id" : ObjectId("5ac4beacc0e2a512e6377d43"),
"document" : "test",
"user" : [
{
"email" : "[email protected]",
"username" : "Anton Held",
"job" : "",
},
{
"email" : "[email protected]",
"username" : "Benny Bill",
"job" : "IT-Officer",
},
{
"email" : "[email protected]",
"username" : "Conny Cenn",
"job" : "",
},
]
}
Therefore I am using this command to get this specific document:
collection.update_one(document{} << "document" << "test"
<< finalize,
document{} << "$set" << open_document <<
(HOW TO DEAL?!) close_document << finalize);
I know that it is possible to update a document with the "update_one"-method (or similar methods like "replace_one", "find_one_and_replace").
But I don't know how to deal with this methods to update as example the username of the existing user with the "email"-element="[email protected]" or how I could add a user to the existing array "user".
Please help me :-)