学习mongo系列(五) AND,$or,$type
MongoDB OR 条件
MongoDB OR 条件语句使用了关键字 $or,语法格式如下:
>db.col.find(
{
$or: [
{key1: value1}, {key2:value2}
]
}
).pretty()
> db.user.find({$or:[{"name":"admin","grade":"99"}]}).pretty()
> db.user.find({$or:[{"name":"admin","grade":"99"}]}).pretty()
> db.user.find({$or:[{"name":"admin"},{"grade":"99"}]}).pretty()
{
"_id" : ObjectId("56946fba3a18f4867aecbcd1"),
"name" : "admin",
"password" : "123456",
"title" : "admin",
"grade" : 50
}
> db.user.find({$or:[{{"grade":"99"},{"name":"admin"}]}).pretty()
...
没太明白$or的究竟
$type
MongoDB 中可以使用的类型如下表所示:
| 类型 | 数字 | 备注 |
|---|---|---|
| Double | 1 | |
| String | 2 | |
| Object | 3 | |
| Array | 4 | |
| Binary data | 5 | |
| Undefined | 6 | 已废弃。 |
| Object id | 7 | |
| Boolean | 8 | |
| Date | 9 | |
| Null | 10 | |
| Regular Expression | 11 | |
| JavaScript | 13 | |
| Symbol | 14 | |
| JavaScript (with scope) | 15 | |
| 32-bit integer | 16 | |
| Timestamp | 17 | |
| 64-bit integer | 18 | |
| Min key | 255 | Query with -1. |
| Max key | 127 |
我们使用的数据库名称为"maxh" 我们的集合名称为"user",以下为我们插入的数据:
> db.user.find().pretty()
{
"_id" : ObjectId("56946fba3a18f4867aecbcd1"),
"name" : "admin",
"password" : "123456",
"title" : "admin",
"grade" : 50
}
{
"_id" : ObjectId("5694714a3a18f4867aecbcd2"),
"name" : "aaaaaaaaa",
"password" : "123456",
"grade" : 99
}
{
"_id" : ObjectId("5694ce6685cf2632ea951c05"),
"name" : "xiaoniao",
"password" : "lijian",
"grade" : "15"
}
查找grade的类型为string(type = 2)类型的记录(行)
> db.user.find({"grade":{$type:2}}).pretty()
{
"_id" : ObjectId("5694ce6685cf2632ea951c05"),
"name" : "xiaoniao",
"password" : "lijian",
"grade" : "15"
}
查找grade的类型为double(数值type = 1)行的记录
> db.user.find({"grade":{$type:1}}).pretty()
{
"_id" : ObjectId("56946fba3a18f4867aecbcd1"),
"name" : "admin",
"password" : "123456",
"title" : "admin",
"grade" : 50
}
{
"_id" : ObjectId("5694714a3a18f4867aecbcd2"),
"name" : "aaaaaaaaa",
"password" : "123456",
"grade" : 99
}
学习mongo系列(五) AND,$or,$type的更多相关文章
- 学习mongo系列(八)密码与权限
一.设置密码及用户角色[1] > db.createUser(... {... user: "maxh",... pwd: "123",... roles ...
- 学习mongo系列(六)limit(munber),skip(number)
> db.user.find().pretty(){ "_id" : ObjectId("56946fba3a18f4867aecbcd1"), &quo ...
- 学习mongo系列(二) 新建数据库,collection ,insert(),save()
一,新建数据库user:use user 二,查看当前使用的数据库:db 三,查看所有数据库:show dbs 四,删除当前正在使用的数据库:db.dropDatabase() 五,在当前数据库中插入 ...
- 学习mongo系列(一) win/mac安装 解析 连接
一.安装mongo数据库 下载链接https://www.mongodb.org/downloads, 在执行如下命令的时候事先按照目录新建如下的目录:(如果数据库安装在D盘就在D盘的根目录下建)&q ...
- Windows-universal-samples学习笔记系列五:Custom user interactions
Custom user interactions Basic input Complex inking Inking Low latency input Simple inking Touch key ...
- 学习mongo系列(十一)关系
准备工作:首先在maxh数据库的address集合中先插入数据 > db.address.insert({child_address:"gansu"}) WriteResul ...
- 学习mongo系列(十)MongoDB 备份(mongodump)与恢复(mongorerstore) 监控(mongostat mongotop)
一.备份 在Mongodb中我们使用mongodump命令来备份MongoDB数据.该命令可以导出所有数据到指定目录中. mongodump命令可以通过参数指定导出的数据量级转存的服务器. mongo ...
- 学习mongo系列(九)索引,聚合,复制(副本集),分片
一.索引 二.聚合 三.复制(副本集) 四.分片 尚未实践操作. 详见http://www.runoob.com/mongodb/mongodb-indexing.html
- 学习mongo系列(七)aggregate() ,$group() 管道
aggregate()聚合,主要用于处理数据(诸如统计平均值,求和等),并返回计算后的数据结果.有点类似sql语句中的 count(*) 接上边的数据库: > db.user.aggregate ...
随机推荐
- libgdx 常见问题
libgdx assets file not found Select Run -> Edit Configurations from the menu In the "Working ...
- myEclipse 界面窗口打不开问题
用的myEclipse版本为2014,在其他工作空间没有此问题,在此工作有此问题. 解决办法: 把当前工作空间视图重置即可
- mysql qps tps计算
Information from web QPS (Query per second) (每秒查询量)TPS(Transaction per second) (每秒事务量,如果是InnoDB会显示,没 ...
- Linux解决Device eth0 does not seem to be present
ifconfig...没有看到eth0..然后重启网卡又报下面错误. 故障现象: service network restartShutting down loopback insterface: ...
- Java 使用jaxp修改节点
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <perso ...
- pod install出现[!] /bin/bash -c错误,Installing Realm报错
pod install出现错误,具体错误信息如下: Installing Realm () [!] /bin/bash -c set -e sh build.sh cocoapods-setup co ...
- RDIFramework.NET ━ 9.14 数据库连接管理 ━ Web部分
RDIFramework.NET ━ .NET快速信息化系统开发框架 9.14 数据库连接管理 -Web部分 我们经常可以看到很多软件直接把数据库连接字符串放在软件执行目录下的配置文件中,这种直接把 ...
- oracle often commands
还是这个好用 Oracle mysql 对比版本 Personal Oracle7 Release 7.3.4.0.0 mysql 3.23.58-nt 启动画面(点击放大) 默认安装目录 C:O ...
- python实现并行爬虫
问题背景:指定爬虫depth.线程数, python实现并行爬虫 思路: 单线程 实现爬虫类Fetcher 多线程 threading.Thread去调Fet ...
- Unity Tidy Tile Pack #1
https://www.assetstore.unity3d.com/cn/#!/content/3276 版本: 1.1 下载地址 密码:mt8a