2

mongodb update with multi true 不会更新所有文档,而只是更新最初的 1 或 2 个文档。这是查询。是因为我使用的限制吗?无论如何,我删除了限制,它仍然没有更新匹配标准找到的所有 31 个文档。猫鼬更新语法有什么问题吗?

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);
4

1 回答 1

4

了解db是 Mongoose 模型后,您需要修改参数列表以与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()
        }}
    },
    { multi: true }, // <== This boolean option goes into the options parameter
    function (err, numberAffected) {
        // Your callback, if needed
    }
);
于 2012-08-15T17:34:49.253 回答