72
rated 0 times
[
74]
[
2]
/ answers: 1 / hits: 15954
/ 10 Years ago, sun, february 23, 2014, 12:00:00
I want to update a MongoDB docment (using the Javascript db driver). I would like to pass in a JSON object and have that update the document ... something like:
Provider.prototype.updateProfile = function(username, profile, callback) {
this.getCollection(function(error, profile_collection) {
if( error ) callback( error );
else {
profile_collection.update(
{username: username},
{profile},
function(error, profile){
if( error ) callback(error);
else callback(null, profile)
});
}
});
};
I want this to be a generic function, so that if the document structure changes I don`t have to re-write. At the moment I can only get this working by using
{$set: {x:profile.x, y:profile.y}}
in the update, does anyone have a generic solutions so that I can pass in any profile:
profile = { .... }
More From » node.js