Mongo使用
在用mongo进行查询时,$exists表示是否document是否包括这个field,即使field的value为null也算是包括。
$exists
Syntax: { 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.
Examples
Exists 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 Values
Given 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/ 页面
Mongo使用的更多相关文章
- 谈一谈NOSQL的应用,Redis/Mongo
1.心路历程 上年11月份来公司了,和另外一个同事一起,做了公司一个移动项目的微信公众号,然后为了推广微信公众号,策划那边需要我们做一些活动,包括抽奖,投票.最开始是没有用过redis的,公司因为考虑 ...
- MongoDB分组汇总操作,及Spring data mongo的实现
转载请在页首注明作者与出处 一:分组汇总 1.1:SQL样例 分组汇总的应用场景非常多,比如查询每个班级的总分是多少,如果用关系形数据库,那么sql是这样子的 ),class from score g ...
- mongo DB for C#
(1)Download the MongoDB C#驱动. http://www.nuget.org/packages/mongocsharpdriver/. (2) Add Reference to ...
- Mongo基础使用,以及在Express项目中使用Mongoose
MongoDB的基本使用 MongoDB特点: 使用BSON存储数据 支持相对丰富的查询操作(相对其他nosql数据库) 支持索引 副本集(支持多个实例/多个服务器运行同个数据库) 分片(数据库水平扩 ...
- 【mongo】mongoVUE使用
1.查询存在字段"test"的项 {"test":{$exists:true}} 2.在表中插入字段 {$set:{"}} 3.正则匹配 {" ...
- mongo遍历表
$mongo = new MongoClient("mongodb://192.168.8.189:27017"); $collectObj = $mongo->select ...
- python & mongo问题记录
背景介绍 使用python操作mongo进行的一些操作记录,为了方便日后可以快速的解决类似问题. 准备工作 为了尽可能简单的说明,我将插入几条简单的数据. from pymongo import Mo ...
- Lind.DDD.Repositories.Mongo层介绍
回到目录 之前已经发生了 大叔之前讲过被仓储化了的Mongodb,而在大叔开发了Lind.DDD之后,决定把这个东西再搬到本框架的仓储层来,这也是大势所趋的,毕竟mongodb是最像关系数据库的NoS ...
- MongoDB基础入门003--使用官方驱动操作mongo,C#
本篇先简单介绍一下,使用官方驱动来操作MongoDB.至于MongoDB原生的增删改查语句,且等以后再慢慢学习. 一.操作MongoDB的驱动主要有两个 1.官方驱动:https://github.c ...
- mongo DB的一般操作
最近接触了一些mongoDB .将一些指令操作记录下来,便于查询和使用 登录 [root@logs ~]# mongo -u loguser -p log123456 --authentication ...
随机推荐
- esp8266 SOC方案经过半年沉淀之后再度重启
我发誓这是最后一次玩esp8266,该脱坑了...... 以前看不懂的教程 http://club.gizwits.com/thread-6447-1-1.html 2018教程 http://clu ...
- git上手简洁手册
下载安装git 创建文件夹:learngit 用Git CMD进入文件夹: cd learngit 用Git CMD初始化git: git init 创建文件:新建一个文件在learngit文件夹下, ...
- MyBatis 之一 简介
什么是 MyBatis ? MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis ...
- IMDB电影排行爬取分析
一.打开IMDB电影T250排行可以看见250条电影数据,电影名,评分等数据都可以看见 按F12进入开发者模式,找到这些数据对应的HTML网页结构,如下所示 可以看见里面有链接,点击链接可以进入电影详 ...
- 牛客多校Round 8
Solved:2 rank:164 签了两个oeis,但这样真的开心嘛
- PHP 加密:Password Hashing API
PHP 5.5 之后引入 Password hashing API 用于创建和校验哈希密码,它属于内核自带,无需进行任何扩展安装和配置.它主要提供了四个函数以供使用: password_hash(): ...
- 了解固态硬盘SSD,竟然如此简单!小白也能懂!
https://www.youtube.com/watch?v=alb6-zp52mA
- Platform 获取主机系统信息
该模块用来访问平台相关属性. 常见属性和方法 1. import platform(pip install platform) 2.获取操作系统名称及版本号 def get_platform(): ...
- mac 中查看监听程序
sudo lsof -nP -iTCP -sTCP:LISTEN | grep mysql
- highcharts图表的常见操作
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...