db2*_*791 1 mongoose mongodb node.js mongodb-query
我正在尝试更新Mongodb中的多个数据库条目:
User.findByIdAndUpdate(req.user._id,
{$push: {people_seen: person_id}},
{$push: {people_liked: person_id}},
function(err, usr){
console.log(req.user);
res.json({success: true});
});
Run Code Online (Sandbox Code Playgroud)
但是,只是people_seen得到了保存.
您正在$push多次使用该运算符.第二个参数findByIdAndUpdate是选项文档.正确$push的语法是:
{ $push: { <field1>: <value1>, ... } }
Run Code Online (Sandbox Code Playgroud)
并且查询中的正确查询是:
User.findByIdAndUpdate(req.user._id,
{ $push: { people_seen: person_id, people_liked: person_id }},
function(err, usr){
console.log(req.user);
res.json({ success: true });
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1949 次 |
| 最近记录: |