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 ...
随机推荐
- Slacklining 2017/2/7
原文 Proline Slacklining's expansion is still in process,but it already has a professional scene.Some ...
- JavaScript中对象的属性:如何遍历属性
for/in 语句循环遍历对象的属性. js中获取key得到某对象中相对应的value的方法:obj.key js中根据动态key得到某对象中相对应的value的方法有二: 一.var key = & ...
- 【page-monitor 前端自动化 中篇】 源码分析
转载文章:来源(靠谱崔小拽) 上篇中初探了page-monitor的一些功能和在前端自动化测试方面的可行性,本篇主要分析下page-monitor的实现方式和源码. mode-module简介 pag ...
- ios之键盘的自定义
一.键盘通知 当文本View(如UITextField,UITextView,UIWebView内的输入框)进入编辑模式成为first responder时,系统会自动显示键盘.成为firstresp ...
- Mac屏幕亮度保存
关于保存屏幕亮度的方法,论坛上已有几种,搜索 NVRAM 会出来很多教程,在此不再详述,可以参考帖子http://www.idelta.info/archives/nvram_on_hackintos ...
- UVa-232-纵横字谜的答案
这一题的话,输出的时候,我们要按照3位输出,不能按照两位,因为是10*10的网格,所以就是100位,不管有没有100的起始格,它都是按照3位进行输出的,从题上的输出可以看到,不然的话,就会PE. 然后 ...
- LeetCode(72) Edit Distance
题目 Given two words word1 and word2, find the minimum number of steps required to convert word1 to wo ...
- 转:Ubuntu下ibus-sunpinyin的安装及翻页快捷键设置!
在windows下,好多人都已经习惯了使用搜狗拼音,到ubuntu下,忽然没有极为顺手的输入法,实为郁闷,但是确实还没有for linux版本的搜狗使用,这是搜狗的商业策略,我们无法掌控,但是,如果你 ...
- 【04】在webstorm里Export declarations are not supported by current JavaScript version
[04]在webstorm里Export declarations are not supported by current JavaScript version Export declara ...
- 动态修改字节码以替换用反射调用get set方法的形式
1. 起因 在前两天,为了解决websphere和JDK8上部署的应用发起webservice调用(框架用的cxf)时报错的问题,跟了一些代码,最终发现可以通过加上参数-Dcom.sun.xml.bi ...