mongodb update with multi true not updating all the documents, rather it just updates the initial 1 or 2 documents. Here is the query. Is it because of the limit I am using ? Anyway, I removed the limit and it is still not updating all 31 documents found by the matching criteria. Is there anything wrong with the mongoose update syntax?
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);
With the understanding that db
is a Mongoose model, you need to modify your parameter list to be compatible with the 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
}
);