mongo 操作符
1 $unset
The $unset
operator deletes a particular field。
https://docs.mongodb.com/manual/reference/operator/update/unset/
2 $in
The $in
operator selects the documents where the value of a field equals any value in the specified array。
https://docs.mongodb.com/manual/reference/operator/query/in/
3 $nin
Syntax: { field: { $nin: [ <value1>, <value2> ... <valueN> ]} } $nin selects the documents where: the field value is not in the specified array or
the field does not exist.
https://docs.mongodb.com/manual/reference/operator/query/nin/
3 $slice
The $slice
operator controls the number of items of an array that a query returns.
https://docs.mongodb.com/manual/reference/operator/projection/slice/
4 $all
The $all
operator selects the documents where the value of a field is an array that contains all the specified elements.
https://docs.mongodb.com/manual/reference/operator/query/all/
5 $and
Syntax: { $and: [ { <expression1> }, { <expression2> } , ... , {<expressionN> } ] } db.inventory.find( { $and: [ { price: { $ne: 1.99 } }, { price: { $exists: true } } ] } )
$and
performs a logical AND
operation on an array of two or more expressions (e.g. <expression1>
, <expression2>
, etc.) and selects the documents that satisfy all the expressions in the array.
https://docs.mongodb.com/manual/reference/operator/query/and/
6 $match
Filters the documents to pass only the documents that match the specified condition(s) to the next pipeline stage.
The $match
stage has the following prototype form:
{ $match: { <query> } }
db.articles.aggregate(
[ { $match : { author : "dave" } } ]
);
7 $group
https://docs.mongodb.com/manual/reference/operator/aggregation/group/
示例:
for i in col.find().limit():
print(i)
{'_id': ObjectId('5698f524a98063dbe9e91ca8'), 'pub_date': '2016-01-12', 'look': '-', 'area': '朝阳', 'title': '【图】95成新小冰柜转让 - 朝阳高碑店二手家电 - 北京58同城', 'url': 'http://bj.58.com/jiadian/24541664530488x.shtml', 'cates': ['北京58同城', '北京二手市场', '北京二手家电', '北京二手冰柜'], 'price': '450 元'}
{'_id': ObjectId('5698f525a98063dbe4e91ca8'), 'pub_date': '2016-01-14', 'look': '-', 'area': '朝阳', 'title': '【图】洗衣机,小冰箱,小冰柜,冷饮机 - 朝阳定福庄二手家电 - 北京58同城', 'url': 'http://bj.58.com/jiadian/24349380911041x.shtml', 'cates': ['北京58同城', '北京二手市场', '北京二手家电', '北京二手洗衣机'], 'price': '1500 元'}
{'_id': ObjectId('5698f525a98063dbe7e91ca9'), 'pub_date': '2015-12-27', 'look': '9成新', 'area': '朝阳', 'title': '台式主机转让 - 朝阳孙河台式机/配件 - 北京58同城', 'url': 'http://bj.58.com/diannao/24440805710645x.shtml', 'cates': ['北京58同城', '北京二手市场', '北京二手台式机/配件', '北京二手台式机'], 'price': ''}
1
pipeline1 = [
{'$match':{'$and':[{'pub_date':{'$gt':'2016-01-02','$lt':'2016-01-15'}},{'area':{'$all':['昌平']}}]}},
{'$group':{'_id':{'$slice':['$cates',,]},'count':{'$sum':}}},
{'$sort':{'count':-}},
{'$limit':},
]
2
pipeline2 = [
{'$match':{'$and':[{'pub_date':{'$gt':'2016-01-02','$lt':'2016-01-15'}},{'look':{'$nin':['-']}}]}},
{'$group':{'_id':'$look','avg_price':{'$max':'$price'}}},
{'$sort':{'avg_price':-}},
{'$limit':},
]
mongo 操作符的更多相关文章
- [Mongo] 解决mongoose不支持条件操作符 $gt$gte:$lte$ne $in $all $not
reference : http://blog.sina.com.cn/s/blog_4df23d840100u25x.html 找到mongoose的安装目录 /usr/local/lib/node ...
- Mongo DB 2.6 需要知道的一些自身限定
在现实的世界中,任何事情都有两面性,在程序的世界中,亦然! 我们不论是在使用一门新的语言,还是一门新的技术,在了解它有多么的让人兴奋,让人轻松,多么的优秀之余,还是很有必要了解一些他的局限性,方便你在 ...
- segmentfault.com mongo出识以及对数组的操作
https://segmentfault.com/a/1190000003951602 首先推荐个工具,no-sql-manager-for-mongodb-professional,虽然收费,但是每 ...
- Mongo中的数组操作
当前mongo中有这么一条数据 book是一个数组,在他后面添加一条数据 { "_id" : ObjectId("5721f504d1f70435632b5ce7&quo ...
- mongo 学习笔记
mysql语句 : ' ,,),(,,) mongo语句: db.}}).limit() db."}) db.}}) 条件操作符1 mongodb中的条件操作符有: (>) 大于 ...
- mongo数据库基础操作
概念 一个mongod服务可以有建立多个数据库,每个数据库可以有多张表,这里的表名叫collection,每个collection可以存放多个文档(document),每个文档都以BSON(binar ...
- Mongo 专题
什么是MongoDB ? MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统. 在高负载的情况下,添加更多的节点,可以保证服务器性能. MongoDB 旨在为WEB应用提供 ...
- mongo中的游标与数据一致性的取舍
除了特殊注释外,本文的测试结果均基于 spring-data-mongodb:1.10.6.RELEASE(spring-boot-starter:1.5.6.RELEASE),MongoDB 3.0 ...
- spring-data-mongodb与mongo shell的对应关系
除了特殊注释外,本文的测试结果均基于 spring-data-mongodb:1.10.6.RELEASE(spring-boot-starter:1.5.6.RELEASE),MongoDB 3.0 ...
随机推荐
- POJ 1947 Rebuilding Roads (树形DP)
题意:给一棵树,在树中删除一些边,使得有一个连通块刚好为p个节点,问最少需要删除多少条边? 思路: 因为任一条边都可能需要被删除,独立出来的具有p个节点的连通块可能在任意一处地方.先从根开始DFS,然 ...
- Fedora19添加和设置YUM源
Fedora19添加和设置YUM源添加yum源前先安装fastestmirror/downloadonly插件和axelget插件: 1.安装fastestmirror/downloadonly插件 ...
- Clusterware 和 RAC 中的域名解析的配置校验和检查 (文档 ID 1945838.1)
适用于: Oracle Database - Enterprise Edition - 版本 10.1.0.2 到 12.1.0.1 [发行版 10.1 到 12.1]Oracle Database ...
- MIPS——循环语句
有关指令 add $t1,$t2,$t3 #寄存器+寄存器,$t1 = $t2 + $t3 add $t1,$t2,immediate #寄存器+立即数,$t1 = $t2 + immediate b ...
- winhex 中磁盘大小与偏移
下图为c盘(活动分区).上方base offset为相对于整个硬盘的字节偏移量.partition 1中信息包括c盘开始扇区,总扇区数.partition 2 信息为扩展分区开始扇区和扇区数.由 P1 ...
- this+call、apply、bind的区别与使用
http://www.ruanyifeng.com/blog/2018/06/javascript-this.html https://segmentfault.com/a/1190000018017 ...
- python之路——目录
目录 python基础部分 基础部分 介绍.基本语法.流程控制 列表 元祖 字符串 字典 集合 文件操作 函数 变量 递归 迭代器,生成器,装饰器,Json和pickle 数据序列化 函数 初识函数 ...
- mac 上node.js环境的安装与测试【转】
http://blog.csdn.net/baihuaxiu123/article/details/51868142 一 摘要 如何大家之前做过web服务器的人都知道,nginx+lua与现在流行的n ...
- 通过工厂模式批量创建对象后调用其中方法 出现XXXis not a function()问题原因
//通过工厂模式批量创建 function Computer(color,weight,logo){ var obj=new Object(); obj.color=c ...
- UVa-156-反片语
这题比较精妙的是,我们对于单词重排,实际上是进行了标准化的处理,即按照字典序排序. 这样的话,就很方便地处理了单词的重排问题,我们不需要使用全排列函数进行排列尝试,我们直接化简为一,然后进行比较就可以 ...