mongodb update + $or 无法准确更新数据

查看:96
本文介绍了mongodb update + $or 无法准确更新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

mongodb $update + $or 无法准确更新数据
使用语句:

db.getCollection('test').update( 
    {$or: [{c1:true, c2: true  }] } ,
    {$set: {rs:  true }},
    {multi:true}
)

需要3行都更新,但是只更新了1行($or被当成了$and)

数据如下:

/* 1 */
{
    "c1" : true
}

/* 2 */
{
    "c2" : true
}

/* 3 */
{
    "c1" : true,
    "c2" : true
}

解决方案

写错啦!注意or的写法。

db.getCollection('test').update( 
    {$or: [{c1:true}, {c2: true  }] } ,
    {$set: {rs:  true }},
    {multi:true}
)

这篇关于mongodb update + $or 无法准确更新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆