I have a document like this:
{
_id : ...,
key : {
a : 1,
b : 2,
c : 3
}
}
And I will update this collection with this:
var data = {
b : 4,
c : 5
};
And I want my document be update to this:
{
_id : ...,
xxx : {
a : 1,
b : 4,
c : 5
}
}
So if I do this:
db.myColl.update( _id , { $set: {"xxx": data } );
it will end up a document like this:
{
_id : ...,
xxx: {
b : 4,
c : 5
}
}
So I have to do it twice:
db.myColl.update( _id , { $set: {"xxx.b": data.b } );
db.myColl.update( _id , { $set: {"xxx.c": data.c } );
Is it possible to do it in single command?
$setreplaces any sub properties with the new values, so if its missing one, it considers that deleted.