博客
关于我
mongodb中比较级查询条件:($lt $lte $gt $gte)(大于、小于)、查找条件
阅读量:794 次
发布时间:2023-02-09

本文共 813 字,大约阅读时间需要 2 分钟。

 

查询表中学生年级大于20,如下:

db.getCollection('student').find({'age':{'$gt':'20'}})

 

$lt    <   (less  than )

$lte    <=  (less than  or equal to )

$gt   >    (greater  than )

$gte   >=    (greater  than or   equal to)

 

$ne  != (not equal to)不等于  {'age': {'$ne': 20}}

$in  在范围内  {'age': {'$in': [20, 23]}}   注意用list

$nin  (not in)  不在范围内{'age': {'$nin': [20, 23]}} 注意用list

$regex (正则匹配) db.collection.find({

'name': {
'$regex''^M.*'}})  匹配以M开头的名字

$exists      属性是否存在       {'name': {'$exists': True}}     查找name属性存在

$type     类型判断        {'age': {'$type': 'int'}}       age的类型为int

$text      文本查询      {'$text': {'$search': 'Mike'}}     text类型的属性中包含Mike字符串

$or  查找多种条件   ({'$or':[{'name':'chen'},{'name':'wang'}]})

 

组合使用方法如下:

db.user.find({"age":{"$gte":18,"$lte":25}})

 

对于日期的条件查询方法:

 

db.getCollection('news').find({'pub_date':{'$gte':'2017-07-11  11:0:0'}})

转载于:https://www.cnblogs.com/williamjie/p/9950558.html

你可能感兴趣的文章
Mac电脑生成git的公私钥(拉取代码更便捷)
查看>>
magento1给customer添加自定义属性
查看>>
Magic Leap是快出产品的节奏,已开放内容开发者注册通道
查看>>
Majorization-Minimization (MM) 和 Successive Convex Approximation (SCA)
查看>>
makefile 打印
查看>>
makefile工作笔记0001---认识使用makefile
查看>>
Makefile遗漏分隔符错误解决
查看>>
malloc和定位new表达式
查看>>
MAMP无法正常启动,错误提示The built-in Apache is active
查看>>
Managing CentOS/RHEL kernel modules.
查看>>
Mangoa-Auth/芒果自助多应用企业级授权系统拥有盗版入库、远程更新等功能
查看>>
MangoDB4.0版本的安装与配置
查看>>
Manjaro 24.1 “Xahea” 发布!具有 KDE Plasma 6.1.5、GNOME 46 和最新的内核增强功能
查看>>
Manjaro 24.2 “Yonada” 发布:尖端功能与精美界面再度进化
查看>>
map 函数返回的列表在使用一次后消失
查看>>
Map 遍历取值及jstl的取值
查看>>
Mapbox GL示例教程【目录】-- 已有80篇
查看>>
Mapped Statements collection already contains value for*
查看>>
mapping文件目录生成修改
查看>>
MapReduce实现二度好友关系
查看>>