当前位置:网站首页>Mongodb aggregation statistics
Mongodb aggregation statistics
2022-07-29 10:19:00 【Unscrupulous pupils】
Grouping statistics
- Count how many are different name The data of 【 {$group: {“_id”: “$name”}} 】
- Each same name How many times has it appeared , Every time , Once 【 count: {$sum: 1} 】
db.event.aggregate(
[{
$group: {
"_id": "$name",
count: {
$sum: 1}
}
}]
)
- Count how many are different name The data of 【 {$group: {“_id”: “$name”}} 】
- Each same name How many times has it appeared , Every time , Count ten times 【 count: {$sum: 10} 】
db.event.aggregate(
[{
$group: {
"_id": "$name",
count: {
$sum: 10}
}
}]
)
Do not group statistics
- Count how many name The data of 【 {$group: {“_id”:null}} 】
- Each same name How many times has it appeared , Every time , Once 【 count: {$sum: 1} 】
db.event.aggregate(
[{
$group: {
"_id": null,
count: {
$sum: 1}
}
}]
)
- All in the statistical table age Total of 【 {$group: {“_id”:null}} 】
- Each same name How many times has it appeared , Every time , Once 【 count: {$sum: “$age”} 】
db.event.aggregate(
[{
$group: {
"_id": null,
count: {
$sum: "$age"}
}
}]
)
Be careful
- Not in groups :“_id” Set to null
- When $ When the symbol appears in the numerical position , Must be added single / Double quotes , Such as {$sum: “$age”} in $age Put quotes
边栏推荐
- 最新翻译的官方PyTorch简易入门教程(PyTorch1.0版本)
- leetcode刷题——排序
- [jetson][转载]jetson上安装pycharm
- How to customize the opportunity closing form in dynamics 365online
- 阿左的境界
- CS assurance and research experience in 2021 (IV): pre promotion and exemption of Xijiao soft Research Institute and the third room of Information Technology Institute
- MySQL infrastructure: SQL query statement execution process
- 关系型数据库之MySQL8——由内而外的深化全面学习
- MySQL logging system: binlog, redo log and undo log
- There is still a chance
猜你喜欢

Unity3d empty package APK error summary

Attachment of text of chenjie Report
![[wechat applet] interface generates customized homepage QR code](/img/9b/cccdb8ff6db61518402a27b94d0196.png)
[wechat applet] interface generates customized homepage QR code
![[jetson][reprint]pycharm installed on Jetson](/img/65/ba7f1e7bd1b39cd67018e3f17d465b.png)
[jetson][reprint]pycharm installed on Jetson

This developer, who has been on the list for four consecutive weeks, has lived like a contemporary college student

"Focus on machines": Zhu Songchun's team built a two-way value alignment system between people and robots to solve major challenges in the field of human-computer cooperation

MySQL优化理论学习指南

Orbslam2 installation test and summary of various problems

跟着武老师学高数——函数、极限和连续(持续更新)

Vim到底可以配置得多漂亮?
随机推荐
Only simple function test? One article takes you to advanced interface automatic testing technology in 6 steps
After E-sports enters Asia, will Tencent be the next "NBA game catcher"?
这才是开发者神器正确的打开方式
综合设计一个OPPE主页--页面的底部
Docker安装Redis、配置及远程连接
英特尔联合Datawhale,发布学习项目!
Several common design methods of test cases [easy to understand]
Selenium series 5-xpath path expression
MySQL infrastructure: SQL query statement execution process
Print out the "hourglass" and the remaining number according to the given number of characters and characters
mosquitto_sub -F 参数使用
Reasons for the rise of DDD and its relationship with microservices
Yin Yi: my learning and growth path
静态资源映射
【微信小程序】接口生成自定义首页二维码
通俗易懂讲解梯度下降法!
This is an incomplete data competition Yearbook!
Skiasharp's WPF self drawn bouncing ball (case version)
Encyclopedia of introduction to machine learning - 2018 "machine learning beginners" official account article summary
Be tolerant and generous