当前位置:网站首页>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
边栏推荐
- Summary of window system operation skills
- HTB-AdmirerToo
- "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
- 还是有机会的
- This is an incomplete data competition Yearbook!
- How to customize the opportunity closing form in dynamics 365online
- Soft exam summary
- After eating Alibaba's core notes of highly concurrent programming, the backhand rose 5K
- Is it safe to open an account online now? Do you want to know that you must go to the business hall to open an account now?
- Sed, regular expression of shell programming
猜你喜欢

Hanyuan high tech Gigabit 2-optical 6-conductor rail managed Industrial Ethernet switch supports X-ring redundant ring network one key ring network switch

Yin Yi: my learning and growth path

HTB-AdmirerToo

跟着田老师学实用英语语法(持续更新)

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

Talk about multithreaded concurrent programming from a different perspective without heap concept

12th generation core processor +2.8k OLED ASUS good screen, lingyao 142022 shadow cyan glaze business thin book

基于SSM实现高校后勤报修系统

Attachment of text of chenjie Report

Easy to understand and explain the gradient descent method!
随机推荐
[HFCTF 2021 Final]easyflask
Some suggestions for programmers to leave single
皕杰报表之文本附件属件
Meituan senior technical expert: DDD's practice in the evolution of tourism e-commerce architecture
MySQL infrastructure: SQL query statement execution process
HTB-AdmirerToo
2018-UperNet ECCV
造型科幻、标配6安全气囊,风行·游艇11.99万起售
Linear regression of machine learning (least square handwriting +sklearn Implementation)
Tips of Day1 practice in 2022cuda summer training camp
Google Earth engine (GEE) -- calculate the location of the center point, the external boundary, the external polygon, fuse and simplify the boundary and return it to the vector set
Reasons for the rise of DDD and its relationship with microservices
[fortran]vscode configure FORTRAN to run Hello World
Where are those test / development programmers in their 30s? a man should be independent at the age of thirty......
The purpose of DDD to divide domains, sub domains, core domains, and support domains
Talk about multithreaded concurrent programming from a different perspective without heap concept
消费电子,冻死在夏天
mosquitto_sub -F 参数使用
Unity3d empty package APK error summary
Several common design methods of test cases [easy to understand]