天天看點

MongoDB聚合(aggregate)

​​https://blog.51cto.com/u_15162069/2758525​​

​​MongoDB聚合(aggregate)​​

一、基礎

1、什麼是聚合?

聚合是基于資料處理的聚合管道,每個文檔通過一個有多個階段(stage)組成的管道

可以對每個階段的管道進行分組、過濾等功能,然後經過一系列的處理,輸出相應的結果

有點像Django中ORM聚合的文法

2、常用管道

MongoDB聚合(aggregate)
MongoDB聚合(aggregate)

3、常用表達式

MongoDB聚合(aggregate)
MongoDB聚合(aggregate)

二、常用管道用法

1、$group

MongoDB聚合(aggregate)
MongoDB聚合(aggregate)

Group by null

補充

MongoDB聚合(aggregate)
MongoDB聚合(aggregate)

2、$project

MongoDB聚合(aggregate)
MongoDB聚合(aggregate)

3、$match

MongoDB聚合(aggregate)
MongoDB聚合(aggregate)

 4、$limit和$skip

MongoDB聚合(aggregate)
MongoDB聚合(aggregate)

5、$unwind

MongoDB聚合(aggregate)
MongoDB聚合(aggregate)
MongoDB聚合(aggregate)
MongoDB聚合(aggregate)
MongoDB聚合(aggregate)
MongoDB聚合(aggregate)
MongoDB聚合(aggregate)
MongoDB聚合(aggregate)
MongoDB聚合(aggregate)
MongoDB聚合(aggregate)
MongoDB聚合(aggregate)
MongoDB聚合(aggregate)
MongoDB聚合(aggregate)
MongoDB聚合(aggregate)
MongoDB聚合(aggregate)
MongoDB聚合(aggregate)