学习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 ...
随机推荐
- PHP文件操作系统----主要的文件操作函数
一.文件操作系统概述 1.概述: php中的文件操作系统主要是对文件和目录的操作.文件在windows系统下分为3种不同:文件.目录.未知,在linux/unix系统下分为7种不同:block.cha ...
- cucumber learning : http://www.cnblogs.com/puresoul/category/340832.html
link Generate cucumber report by json website Sample as json file for cucumber report: [ { "key ...
- Nest查询示例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- php基础篇-二维数组排序 array_multisort
原文:php基础篇-二维数组排序 array_multisort 对2维数组或者多维数组排序是常见的问题,在php中我们有个专门的多维数组排序函数,下面简单介绍下: array_multisort(a ...
- resx文件在X64位编译,提示“未能加载文件或程序集”的问题?
原文:resx文件在X64位编译,提示"未能加载文件或程序集"的问题? resx文件在X64位编译,提示"未能加载文件或程序集"的问题? 解答: 错误现象如下 ...
- cocos2d-x场景切换动画
void StartScene::beginGame() { CCLog("beginGame"); //CCTransitionScene *trans ...
- nsurl 测试ATS
LIPEIdeMacBook-Air:~ lipei$ nscurl --ats-diagnostics https://xxxxx.com/ Starting ATS Diagnostics Con ...
- RDIFramework.NET ━ 9.16 案例模块━ Web部分
RDIFramework.NET ━ .NET快速信息化系统开发框架 9.15 案例模块 -Web部分 9.16.1.产品管理模块 产品管理模块提供了基本的增.删.改.查.导出.分页等的实现,用户可 ...
- 多列布局——column-count
column-count属性主要用来给元素指定想要的列数和允许的最大列数.其语法规则: column-count:auto | <integer> 取值说明: 属性值 属性值说明 auto ...
- 微信端应用 ionic实现texarea 自适应高度
最近公司项目,做微信端用到texarea 需要实现自适应高度的功能 当然自适应高度的方法很多网上找一大片,最直接的方式就是在使用到texarea的controller中添加js代码事件来实现,这中方式 ...