Assume that I have a document in database which has the following structure;
id: 1,
name: alex,
age: 21
There are some updates in client side and the same document with id:1 returns as;
id: 1,
name: alex,
age: 21,
location: usa
where a new field location is added.
I want to update the document in database. I want to add this new inserted field but I couldn't find out how can I handle this situation. Because location is not static, it can be surname, job and so on. So new inserted fields are dynamic and I don't know in advance.
If the field location was static, I could write a query as;
db.collection("user").updateOne( {id: 1},
{$set: {name: "alex", age: "21", location: "usa"}}, function(err, result){
if(err){}
else{}
});
But now, how can I update the document with this newly added fields?