学习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 ...
随机推荐
- DataTable使用技巧总结【转】
一.DataTable简介 ()构造函数 DataTable() 不带参数初始化DataTable 类的新实例. DataTable(string tableName) 用指定的表名初始化DataTa ...
- 临时存存储页面上的数据---js中的cookie
实现的效果: 当点击某个按钮的时候,实现点击A的同时,弹出B的注册div,使填写在B信息数据保存下来,点击B的确定按钮,B消失,A的图标往后移动一格,原来的位置为图标C,点击C可以弹出来一个链接的页面 ...
- oracle创建、删除账户
1.创建 /*第1步:创建表空间 */create tablespace xybi datafile 'E:\oracle\oradata\zzxe\xybi_d01' size 100M ; /*第 ...
- (copy) Shell Script to Check Linux System Health
source: http://linoxide.com/linux-shell-script/shell-script-check-linux-system-health/ This article ...
- Java学习——Number类、Character类
Number类 在使用数字时,我们通常会使用内置数据类型,如 int a = 9; float b = 3.14 然而在实际开发中,我们经常遇到需要使用对象而不是使用内置数据类型的对象.为了解决这一问 ...
- 使用MapReduce实现一些经典的案例
在工作中,很多时候都是用hive或pig来自动化执行mr统计,但是我们不能忘记原始的mr.本文记录了一些通过mr来完成的经典的案例,有倒排索引.数据去重等,需要掌握. 一.使用mapreduce实现倒 ...
- 关于thenao.scan() fn函数参数的说明
theano.scan()原型: theano.scan( fn, sequences=None, outputs_info=None, non_sequences=None, n_steps=Non ...
- Leetcode: Repeated Substring Pattern
Given a non-empty string check if it can be constructed by taking a substring of it and appending mu ...
- Leetcode: Pacific Atlantic Water Flow
Given an m x n matrix of non-negative integers representing the height of each unit cell in a contin ...
- Android--Retrofit+RxJava的简单封装(三)
1,继续接着上一篇的讲讲,话说如果像上一篇这样的话,那么我们每一次请求一个结构都要创建一堆的Retrofit对象,而且代码都是相同的,我们可以试试封装一下 先创建一个HttpMethods类,将Ret ...