MongoDB权威指南-第7章

MongoDB权威指南
聚合
7.1-聚合框架
db.articles.arregate({“project":{"author":1}},{"$group":{"_id":"author","count":{"$sum":1}}},{"$sort":{"count":-1}},{"$limit”:5})  
            聚合的结果必须限制在16MB以内(MongoDB支持的最大响应消息大小)  
        7.2-管道操作符
match
match,使 match放在管道的前面位置
project使iddb.articles.arregate($project:author:1,id:0)db.articles.arregate($project":"newFieldName":"$originalFieldName","$sort:newFieldName:1)使2 add
subtract multiply
divide mod
ex
db.employees.arregate({“project":{"totalPay":{"$add":["$salary","$bonus”]}}})  
                        db.employees.arregate({“$project":{"totalPay":{"$subtract":[{"$add":["$salary","$bonus”]},”401k”]}}})  
                3-日期表达式
year
month dayOfMonth
dayOfWeek dayOfYear
hour minute
secondexdb.employees.arregate($project":"hiredIn":"$month":"$hireDate)4 substr
concat toLower
toUpper5 cmp
strcasecmp and
or not
cond ifNull
group$group":"id":"state":"$state","city":"$citydb.employees.arregate($group":"id":"$country","totalRevenue":"$sum":"$revenue)db.employees.arregate($group":"id":"$country","lowestScore":"$min":"$score","highestScore":"$max":"$score) addToSet
push unwind
拆分unwind可以将数组中的每个值拆分为单独的文档
sort limit
skip使MongoDBMongoDB207.3MapReduceMongoDBMapReduce7.4countdistinctgroupgroup7.1db.articles.arregate($project":"author":1,"$group":"id":"author","count":"$sum":1,"$sort":"count":1,"$limit:5)16MB(MongoDB)7.2 match
match,使 match放在管道的前面位置
project使iddb.articles.arregate($project:author:1,id:0)db.articles.arregate($project":"newFieldName":"$originalFieldName","$sort:newFieldName:1)使2 add
subtract multiply
divide mod
ex
db.employees.arregate({“project":{"totalPay":{"$add":["$salary","$bonus”]}}})  
                    db.employees.arregate({“$project":{"totalPay":{"$subtract":[{"$add":["$salary","$bonus”]},”401k”]}}})  
            3-日期表达式
year
month dayOfMonth
dayOfWeek dayOfYear
hour minute
secondexdb.employees.arregate($project":"hiredIn":"$month":"$hireDate)4 substr
concat toLower
toUpper5 cmp
strcasecmp and
or not
cond ifNull
group$group":"id":"state":"$state","city":"$citydb.employees.arregate($group":"id":"$country","totalRevenue":"$sum":"$revenue)db.employees.arregate($group":"id":"$country","lowestScore":"$min":"$score","highestScore":"$max":"$score) addToSet
push unwind
拆分unwind可以将数组中的每个值拆分为单独的文档
sort limit
$skip
使用管道
MongoDB不允许单一的聚合操作占用过多的系统内存
如果MongoDB发现某个聚合操作占用了20%以上的内存,这个操作就会直接输出错误
7.3-MapReduce
找出集合中的所有键
网页分类
MongoDB和MapReduce
7.4-聚合命令
count
distinct
group
group可以执行更复杂的聚合

DISSIDIA思维导图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值