Mongo使用
来源:互联网 发布:玻璃优化软件破解版 编辑:程序博客网 时间:2024/05/16 03:16
在用mongo进行查询时,$exists表示是否document是否包含这个field,即使field的value为null也算是包含。
$existsSyntax: { field: { $exists: <boolean> } }When <boolean> is true, $exists matches the documents that contain the field, including documents where the field value is null. If <boolean> is false, the query returns only the documents that do not contain the field.ExamplesExists and Not Equal ToConsider the following example:db.inventory.find( { qty: { $exists: true, $nin: [ 5, 15 ] } } )This query will select all documents in the inventory collection where the qty field exists and its value does not equal 5 or 15.Null ValuesGiven a collection named records with the following documents:{ a: 5, b: 5, c: null }{ a: 3, b: null, c: 8 }{ a: null, b: 3, c: 9 }{ a: 1, b: 2, c: 3 }{ a: 2, c: 5 }{ a: 3, b: 2 }{ a: 4 }{ b: 2, c: 4 }{ b: 2 }{ c: 6 }Consider the output of the following queries:Query: db.records.find( { a: { $exists: true } } )Result: { a: 5, b: 5, c: null }{ a: 3, b: null, c: 8 }{ a: null, b: 3, c: 9 }{ a: 1, b: 2, c: 3 }{ a: 2, c: 5 }{ a: 3, b: 2 }{ a: 4 }Query: db.records.find( { b: { $exists: false } } )Result: { a: 2, c: 5 }{ a: 4 }{ c: 6 }Query: db.records.find( { c: { $exists: false } } )Result: { a: 3, b: 2 }{ a: 4 }{ b: 2 }
而要查看document中哪些field的值为null,则需要用$in 来查询。详情可以参考http://docs.mongodb.org/manual/reference/operator/query/in/ 页面
0 0
- mongo使用
- Mongo使用
- mongo 使用 in操作
- mongo使用经验谈
- mongo认识与使用
- mongo第一次使用
- connect-mongo使用简介
- Mongo入门使用(一)
- 使用mongo命令
- mongo update 使用
- mongo认识与使用
- yii1.x 使用mongo
- mongo $where的使用
- python使用mongo数据库
- Mongo使用命令
- mongo的sum使用
- mongo redis使用
- Mongo基本使用
- Oracle GoldenGate Install For Linux
- LeetCode之旅(1)
- Rotate List
- 行内元素与块级元素比较全面的区别和转换
- Convert Sorted Array to Binary Search Tree
- Mongo使用
- 《javascript设计模式》读书笔记二(封装和隐藏信息)
- 互换两个变量,不使用中间变量
- 2015届毕业生的找工作记录
- 杨辉三角
- Android:自定义Button
- POJ 3469 最大流
- 列的软件包有不能满足的依赖关系:libgnomeprint2.2-dev: 依赖: libpango1.0-dev 但是它将不会被安装
- 文件的输入输出 C++