当前位置:网站首页>MongoDB 多字段聚合Group by
MongoDB 多字段聚合Group by
2022-06-13 05:34:00 【唐三水】
1、多屬性聚合 匯總 按照
三個屬性 senderId","msgExt.rUserId","msgExt.cId 聚合統計數量
db.getCollection("user_message").aggregate([{$group : {
_id :{senderId:"$senderId",
rUserId: "$msgExt.rUserId",
cId: "$msgExt.cId"} ,
num_tutorial : {$sum : 1 }}}]);得到結果如下

2、篩選上述count >1的數據
使用match關鍵字:
db.getCollection("user_message").aggregate([{$group : {
_id :{senderId:"$senderId",
rUserId: "$msgExt.rUserId",
cId: "$msgExt.cId"} ,
total_num : {$sum : 1 }}},
{$match: {
total_num: {$gt: 1}}}]);
3、求集合總數
db.user_message.count();
边栏推荐
- C calls the API and parses the returned JSON string
- System file interface open
- 若依框架=》如何设置导入导出模板全局为文本格式(解决科学计数问题)
- Unity game optimization [Second Edition] learning record 6
- Std:: Map initialization
- redis
- About anonymous inner classes
- Dynamic and static libraries
- The 13th week of the second semester of sophomore year
- 2021-9-19
猜你喜欢

powershell优化之一:提示符美化

Problems encountered in the use of PgSQL

Search DFS and BFS

安装harbor(在线|离线)

Case - simulated landlords (upgraded version)

Mysql database crud operation

Web site learning and sorting

Automatic database backup (using Navicat)

ZABBIX proxy, sender (without agent monitoring), performance optimization

Quartz basic use
随机推荐
Use of natural sorting comparable
Dup2 use
Case - traversing the directory (file class & recursive call)
System file interface open
[multi thread programming] the future interface obtains thread execution result data
【转载】C语言内存和字符操作函数大全
17.6 unique_ Lock details
Solve the problem of garbled code in the MySQL execution SQL script database in docker (no need to rebuild the container)
Time display of the 12th Blue Bridge Cup
Mysql database backup and restore:
Float type value range
Course outline of market drawing 1- basic knowledge
Understanding of speech signal framing
KVM virtualization management tool
Case - the ArrayList collection stores student objects and traverses them in three ways
One of PowerShell optimizations: prompt beautification
RT thread console device initialization
SQL table columns and statements of database
Fast power code
Redis plus instructions