七、mongodb之逻辑查询运算符

#                       mongodb之逻辑查询运算符

###1、逻辑查询运算符

运算符含义
$exists连接多个查询语句,返回同时符合的
$not一个查询语句,返回不符合这个查询语句的
$nor连接多个查询语句,返回不符合这些查询语句的
$or连接多个查询语句,返回符合其中一个查询语句的

###2、and运算符

$and(且)连接多个查询语句,在中括号[]里面表示,

db.inventory.find( { $and: [ { price: { $ne: 1.99 } }, { price: { $exists: true } } ] } )

db.inventory.find( {
    $and : [
        { $or : [ { price : 0.99 }, { price : 1.99 } ] },
        { $or : [ { sale : true }, { qty : { $lt : 20 } } ] }
    ]
} )

###3、not运算符

作用在field后面,用在查询条件前:
db.inventory.find( { price: { $not: { $gt: 1.99 } } } )

支持正则匹配:
db.inventory.find( { item: { $not: /^p.*/ } } )

###4、nor运算符

连接多个:
db.inventory.find( { $nor: [ { price: 1.99 }, { sale: true } ]  } )

db.inventory.find( { $nor: [ { price: 1.99 }, { price: { $exists: false } },
                             { sale: true }, { sale: { $exists: false } } ] 
                   } )

###5、or运算符

连接多个:

db.inventory.find( { $or: [ { quantity: { $lt: 20 } }, { price: 10 } ] } )
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值