使用multi的mongodb更新不更新所有文档,而只更新初始的1或2个文档。这是查询。是因为我使用的限制吗?无论如何,我删除了限制,它仍然没有更新匹配条件找到的所有31个文件。 mongoose更新语法有什么问题吗?
db.update({biztype:msg.biztype, 'g_location': {$near: [msg.lng, msg.lat], $maxDistance:10/111.12}},{
$push:{fromusers:{
ip: ip,
msg: msg.msg,
u_name: msg.name,
u_mobile: msg.mobile,
u_email: msg.email,
comment_date: new Date()
}}
}, false, true).
limit(10);
答案 0 :(得分:4)
了解db
是一个Mongoose模型,您需要修改参数列表以与Mongoose update兼容:
db.update({biztype:msg.biztype, 'g_location': {$near: [msg.lng, msg.lat], $maxDistance:10/111.12}},
{
$push:{fromusers:{
ip: ip,
msg: msg.msg,
u_name: msg.name,
u_mobile: msg.mobile,
u_email: msg.email,
comment_date: new Date()
}}
},
{ multi: true }, // <== This boolean option goes into the options parameter
function (err, numberAffected) {
// Your callback, if needed
}
);