当前位置:网站首页>MongoDB 之聚合查询
MongoDB 之聚合查询
2022-08-06 05:21:00 【我叫向同学】
聚合查询
MongoDB 中聚合(aggregate)主要用于处理数据(诸如统计平均值,求和等),并返回计算后的数据结果。有点类似 SQL 语句中的 count(*)。
聚合的表达式:
测试一下
插入测试数据
{
title: 'MongoDB Overview',
description: 'MongoDB is no sql database',
by_user: 'runoob.com',
url: 'http://www.runoob.com',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 100
}
{
title: 'NoSQL Overview',
description: 'No sql database is very fast',
by_user: 'runoob.com',
url: 'http://www.runoob.com',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 10
}
{
title: 'Neo4j Overview',
description: 'Neo4j is no sql database',
by_user: 'Neo4j',
url: 'http://www.neo4j.com',
tags: ['neo4j', 'database', 'NoSQL'],
likes: 750
}

aggregate() 方法
MongoDB中聚合的方法使用aggregate()。计算每个作者写的文章数
db.test.aggregate([{$group : {_id : "$by_user", num_tutorial : {$sum : 1}}}])
$group:以id进行分组
num_tutorial :结果别名
sum :是否求和,1为真

边栏推荐
- Design and Implementation Analysis of Intelligent Monitoring System in Power Distribution Room-Susie Zhou
- PointNet和PointNet++论文解读
- 独立看门狗和窗口看门狗
- 从零开始学编程——环境配置
- Retrofit的简单使用和源码分析
- [MM32] eMiniBoard's PWM drive passive buzzer + ADC to adjust LED brightness reference routine (on)
- MiniFlow -- 7.简单理解梯度下降
- STM32DMA
- RTSP视频流显示(海康威视)
- 惯性传感器实现全身姿态检测
猜你喜欢

安科瑞预付费平台关于电改政策的设计与应用-Susie 周

【STM32F4系列】【HAL库】【自制库】W25QXX FLASH驱动
![[MM32] eMiniBoard's PWM drive passive buzzer + ADC to adjust LED brightness reference routine (on)](/img/3f/8528c231fc74ae095af8fa9c77e760.png)
[MM32] eMiniBoard's PWM drive passive buzzer + ADC to adjust LED brightness reference routine (on)

Altium Designer18基本使用

VTK渲染颜色

Design and Implementation Analysis of Intelligent Monitoring System in Power Distribution Room-Susie Zhou

求二进制中 1 的个数的几个解法

A Brief Talk on the Application Significance of Campus Energy Consumption Monitoring and Management Platform-Susie Zhou

从零开始学编程——环境配置

Application of Ankerui Substation Integrated Automation System in Substation-Susie Week
随机推荐
VS 利用命令行参数批量读取处理数据
Ankerui's campus electrical design research based on the concept of energy saving and emission reduction-Susie Week
【Home-Assistant 安装】
Ankerui DTSD1352-10(80)A Straight-through Wiring Instructions and Precautions-Susie Zhou
【STM32HAL库】常用功能备忘
浅谈高速公路服务区分布式光伏并网发电-Susie 周
【STM32F4系列】【HAL库】【自制库】W25QXX FLASH驱动
VS报错合集(持续更新ing)
物联网技术在智慧电网中的应用-Susie 周
【STM32标准库】【自制库】NEC协议的红外解码和发送
文献阅读:卷积神经网络在图像识别中的应用研究综述
Retrofit的简单使用和源码分析
深度学习框架拾遗:【Pytorch(三)】——Pytorch结构化数据建模流程
深度学习框架拾遗:【Pytorch(七)】——Pytorch动态计算图
【STM32F4系列】【自制库】读取并模拟遥控插座的遥控器
浅谈数据中心供配电设计应用以及监控产品选型-Susie 周
#ifndef#define#endif笔记
【基础知识】SPI通信协议
题解 | #链表内指定区间反转#
【STM32】【HAL库】【实用制作】数控收音机(硬件设计)