如何在我的Node应用程序中运行以下命令?
db.users.update(
{ "username": "steve" },
{ $push:
{
likes: [ { "user_id": "3" } ]
}
}
)
我通过Mongoose设置了架构,但我不确定是否可以运行这个原始的Mongo命令。
答案 0 :(得分:1)
Updating docs using Mongoose应该可以帮到你。以下内容可帮助您使用mongoose更新文档:
Model.update(
{"username":"steve"},
{$push: {
likes: [ { "user_id": "3" } ]
}
},
//if you have any options mention here(options),
//A callback comes here (optional)
)
以下是使用Mongoose作为参考的更新命令的语法:
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
})