Reputation: 139
How do I run the following command within my Node application?
db.users.update(
{ "username": "steve" },
{ $push:
{
likes: [ { "user_id": "3" } ]
}
}
)
I have a schema setup via Mongoose but I'm not sure if it's possible to run this raw Mongo command.
Upvotes: 0
Views: 146
Reputation: 5091
Updating docs using Mongoose should help you. The following should help you update docs using mongoose:
Model.update(
{"username":"steve"},
{$push: {
likes: [ { "user_id": "3" } ]
}
},
//if you have any options mention here(options),
//A callback comes here (optional)
)
Here is the syntax of update command using Mongoose for your reference:
var conditions = { name: 'borne' }
, update = { $inc: { visits: 1 }}
, options = { multi: true };
Model.update(conditions, update, options, callback);
function callback (err, numAffected) {
// numAffected is the number of updated documents
})
Upvotes: 1