MongoDB atomic update via 'merge' document -
i know can atomically update existing mongo document setting specific fields. following code it:
var update = mongodb.driver.builders.update.set("insidelegmeasurement", 32.4); safemoderesult result = personcollection.update(query, update, updateflags.multi,safemode.true);
however, can atomically update several fields passing in document want 'merge' existing doc? imagine have document follows: {"favcolor":"red","favfood":"pasta"} , want update existing doc these values. want this:
var update = mongodb.driver.builders.update.merge({"favcolor":"red","favfood":"pasta"});
or even
var update = mongodb.driver.builders.update.merge(myupdatebsondoc);
where mybsondocument contains lots of fields don't want have 'unpack' doc merged original.
is possible somehow?
thanks
found answer:
//var snippetjson= '{title:"tin machine ii",brandnewfield:"this gets added nicely"}'; mongodb.bson.bsondocument updatedoc = mongodb.bson.serialization.bsonserializer.deserialize<bsondocument>(snippetjson); var update = new updatedocument { { "$set", updatedoc } };
easy when know how!
Comments
Post a Comment