Docs 菜单

Docs 主页开发应用程序MongoDB Manual

$setWindowFields(聚合)

在此页面上

  • 定义
  • 语法
  • 行为
  • 窗口运算符
  • 限制
  • 举例
$setWindowFields

版本 5.0 中的新增功能

对集合中指定范围的文档(称为窗口)执行操作,并根据所选的窗口运算符返回结果。

例如,您可以使用$setWindowFields阶段输出:

  • 集合中两个文档之间的销售额差异。

  • 销售排名。

  • 累计销售总额。

  • 分析复杂的时间序列信息,而无需将数据导出到外部数据库。

$setWindowFields阶段语法:

{
$setWindowFields: {
partitionBy: <expression>,
sortBy: {
<sort field 1>: <sort order>,
<sort field 2>: <sort order>,
...,
<sort field n>: <sort order>
},
output: {
<output field 1>: {
<window operator>: <window operator parameters>,
window: {
documents: [ <lower boundary>, <upper boundary> ],
range: [ <lower boundary>, <upper boundary> ],
unit: <time unit>
}
},
<output field 2>: { ... },
...
<output field n>: { ... }
}
}
}

$setWindowFields阶段接受包含以下字段的文档:

字段
必要性
说明
partitionBy
Optional

指定用于对文档进行分组的表达式。在$setWindowFields阶段,文档组称为分区。默认为整个集合的一个分区。

对于某些操作符是必需的(请参阅限制)

指定分区中用于对文档进行排序的字段。使用与 $sort 阶段相同的语法。默认为不排序。

必需

指定要附加到$setWindowFields阶段返回的输出中的文档的字段。每个字段都设置为窗口操作符返回的结果。

字段可以包含来指定嵌入式文档字段和数组字段。 $setWindowFields阶段中嵌入式文档点状表示法的语义与$addFields$set阶段相同。请参阅嵌入式文档 $addFields 示例嵌入式文档 $set 示例。

Optional

指定窗口边界和参数。窗口边界是包含性的。默认为无边界窗口,包括分区中的所有文档。

指定文档范围窗口。

Optional

一个窗口,其中的上下界是相对于从集合中读取的当前文档的位置指定的。

窗口边界是使用包含下限和上限字符串或整数的双元素数组指定的。使用:

  • 输出中当前文档位置的 "current" 字符串。

  • 分区中第一个或最后一个文档位置的 "unbounded" 字符串。

  • 相对于当前文档的位置,可以用整数表示。对于当前文档之前的位置,可以使用负整数。对于当前文档之后的位置,可以使用正整数。0 是当前文档位置。

请参阅文档窗口示例。

Optional

在该窗口中,使用基于当前文档中sortBy字段的一系列值来定义下边界和上边界。

窗口边界是使用包含下限和上限字符串或数字的双元素数组指定的。使用:

  • 输出中当前文档位置的 "current" 字符串。

  • 分区中第一个或最后一个文档位置的 "unbounded" 字符串。

  • 要添加到当前文档的sortBy字段值的数字。如果sortBy字段值包含在下限和上限边界内,则文档位于窗口中。

请参阅范围窗口示例。

Optional

指定时间范围窗口边界的单位。可以设置为以下字符串之一:

  • "year"

  • "quarter"

  • "month"

  • "week"

  • "day"

  • "hour"

  • "minute"

  • "second"

  • "millisecond"

如果省略,则使用默认的数值范围窗口边界。

请参阅时间范围窗口示例。

提示

另请参阅:

$setWindowFields阶段将新字段附加到现有文档。您可以在聚合操作中包含一个或多个$setWindowFields阶段。

$setWindowFields 阶段不保证返回文档的顺序。

这些操作符可与$setWindowFields阶段一起使用:

$setWindowFields阶段的限制:

  • MongoDB 5之前的版本。 3时,无法使用$setWindowFields阶段:

  • sortBy用于以下操作:

  • 范围窗口要求所有sortBy值都是数字。

  • 时间范围窗口要求所有sortBy值都是日期。

  • 范围时间范围窗口只能包含一个sortBy字段,并且排序必须为升序。

  • 不能同时指定文档窗口和范围窗口。

  • 这些操作符使用隐式窗口,如果指定窗口选项,则会返回错误:

  • 对于范围窗口,窗口中只包含指定范围内的数字。不包括缺失值、未定义值和null值。

  • 对于时间范围窗口:

    • 窗口中只包含日期和时间类型。

    • 数值边界值必须为整数。例如,您可以使用 2 小时作为边界,但不能使用 1.5 小时。

  • 对于空窗口或具有不兼容值的窗口(例如,对字符串使用 $sum),返回值取决于操作符:

    • 对于$count$sum,返回值为0

    • $addToSet$push 的返回值为空数组。

    • 对于所有其他运算符,返回值为 null

创建cakeSales集合,其中包含加利福尼亚州 ( CA ) 和华盛顿州 ( WA ) 的蛋糕销售情况:

db.cakeSales.insertMany( [
{ _id: 0, type: "chocolate", orderDate: new Date("2020-05-18T14:10:30Z"),
state: "CA", price: 13, quantity: 120 },
{ _id: 1, type: "chocolate", orderDate: new Date("2021-03-20T11:30:05Z"),
state: "WA", price: 14, quantity: 140 },
{ _id: 2, type: "vanilla", orderDate: new Date("2021-01-11T06:31:15Z"),
state: "CA", price: 12, quantity: 145 },
{ _id: 3, type: "vanilla", orderDate: new Date("2020-02-08T13:13:23Z"),
state: "WA", price: 13, quantity: 104 },
{ _id: 4, type: "strawberry", orderDate: new Date("2019-05-18T16:09:01Z"),
state: "CA", price: 41, quantity: 162 },
{ _id: 5, type: "strawberry", orderDate: new Date("2019-01-08T06:12:03Z"),
state: "WA", price: 43, quantity: 134 }
] )

以下示例使用 cakeSales 集合。

此示例使用 中的 文档 $setWindowFields窗口来输出每个 的累积蛋糕销量quantity state

db.cakeSales.aggregate( [
{
$setWindowFields: {
partitionBy: "$state",
sortBy: { orderDate: 1 },
output: {
cumulativeQuantityForState: {
$sum: "$quantity",
window: {
documents: [ "unbounded", "current" ]
}
}
}
}
}
] )

在示例中:

  • partitionBy: "$state"state对集合中的文档进行分区CAWA都有分区。

  • sortBy: { orderDate: 1 }orderDate以升序 ( 1 ) 对每个分区中的文档进行排序,因此最早的orderDate位于最前面。

  • output

    • cumulativeQuantityForState 字段设置为每个state 的累积 quantity ,该值是通过将分区内的前一个值累加而得到的。

    • 使用在quantity 文档$sum 窗口中运行的 操作符计算累积 。

      窗口包含介于unbounded下限和current文档之间的文档。这意味着$sum会返回分区开头和当前文档之间文档的累积quantity

在此示例输出中,CAWA 的累积 quantity 数组会显示在 cumulativeQuantityForState 字段中:

{ "_id" : 4, "type" : "strawberry", "orderDate" : ISODate("2019-05-18T16:09:01Z"),
"state" : "CA", "price" : 41, "quantity" : 162, "cumulativeQuantityForState" : 162 }
{ "_id" : 0, "type" : "chocolate", "orderDate" : ISODate("2020-05-18T14:10:30Z"),
"state" : "CA", "price" : 13, "quantity" : 120, "cumulativeQuantityForState" : 282 }
{ "_id" : 2, "type" : "vanilla", "orderDate" : ISODate("2021-01-11T06:31:15Z"),
"state" : "CA", "price" : 12, "quantity" : 145, "cumulativeQuantityForState" : 427 }
{ "_id" : 5, "type" : "strawberry", "orderDate" : ISODate("2019-01-08T06:12:03Z"),
"state" : "WA", "price" : 43, "quantity" : 134, "cumulativeQuantityForState" : 134 }
{ "_id" : 3, "type" : "vanilla", "orderDate" : ISODate("2020-02-08T13:13:23Z"),
"state" : "WA", "price" : 13, "quantity" : 104, "cumulativeQuantityForState" : 238 }
{ "_id" : 1, "type" : "chocolate", "orderDate" : ISODate("2021-03-20T11:30:05Z"),
"state" : "WA", "price" : 14, "quantity" : 140, "cumulativeQuantityForState" : 378 }

此示例使用 中的 文档 $setWindowFields窗口输出quantity 中每个$year 的累积蛋糕销量orderDate

db.cakeSales.aggregate( [
{
$setWindowFields: {
partitionBy: { $year: "$orderDate" },
sortBy: { orderDate: 1 },
output: {
cumulativeQuantityForYear: {
$sum: "$quantity",
window: {
documents: [ "unbounded", "current" ]
}
}
}
}
}
] )

在示例中:

  • partitionBy: { $year: "$orderDate" } 中的$year 对集合中的文档进行orderDate 分区 。2019 2020、 和2021 都有分区。

  • sortBy: { orderDate: 1 }orderDate以升序 ( 1 ) 对每个分区中的文档进行排序,因此最早的orderDate位于最前面。

  • output

    • cumulativeQuantityForYear 字段设置为每年的累积 quantity,这个值通过对分区中先前值的连续添加而增加。

    • 使用在quantity 文档$sum 窗口中运行的 操作符计算累积 。

      窗口包含介于unbounded下限和current文档之间的文档。这意味着$sum会返回分区开头和当前文档之间文档的累积quantity

在此示例输出中,每年的累计 quantity 显示在 cumulativeQuantityForYear 字段中:

{ "_id" : 5, "type" : "strawberry", "orderDate" : ISODate("2019-01-08T06:12:03Z"),
"state" : "WA", "price" : 43, "quantity" : 134, "cumulativeQuantityForYear" : 134 }
{ "_id" : 4, "type" : "strawberry", "orderDate" : ISODate("2019-05-18T16:09:01Z"),
"state" : "CA", "price" : 41, "quantity" : 162, "cumulativeQuantityForYear" : 296 }
{ "_id" : 3, "type" : "vanilla", "orderDate" : ISODate("2020-02-08T13:13:23Z"),
"state" : "WA", "price" : 13, "quantity" : 104, "cumulativeQuantityForYear" : 104 }
{ "_id" : 0, "type" : "chocolate", "orderDate" : ISODate("2020-05-18T14:10:30Z"),
"state" : "CA", "price" : 13, "quantity" : 120, "cumulativeQuantityForYear" : 224 }
{ "_id" : 2, "type" : "vanilla", "orderDate" : ISODate("2021-01-11T06:31:15Z"),
"state" : "CA", "price" : 12, "quantity" : 145, "cumulativeQuantityForYear" : 145 }
{ "_id" : 1, "type" : "chocolate", "orderDate" : ISODate("2021-03-20T11:30:05Z"),
"state" : "WA", "price" : 14, "quantity" : 140, "cumulativeQuantityForYear" : 285 }

此示例使用 中的 文档 $setWindowFields窗口输出蛋糕销售quantity 的移动平均值:

db.cakeSales.aggregate( [
{
$setWindowFields: {
partitionBy: { $year: "$orderDate" },
sortBy: { orderDate: 1 },
output: {
averageQuantity: {
$avg: "$quantity",
window: {
documents: [ -1, 0 ]
}
}
}
}
}
] )

在示例中:

  • partitionBy: "$orderDate" 中的$year 对集合中的文档进行orderDate 分区 。2019 2020、 和2021 都有分区。

  • sortBy: { orderDate: 1 }orderDate以升序 ( 1 ) 对每个分区中的文档进行排序,因此最早的orderDate位于最前面。

  • output

    • averageQuantity 字段设置为每年的移动平均值 quantity

    • 使用quantity 文档$avg 窗口中运行的 操作符计算移动平均值 。

      窗口包含介于-10之间的文档。这意味着$avg会返回分区中当前文档 ( -1 ) 和当前文档 ( 0 ) 之前的文档之间的移动平均值quantity

在此示例输出中,移动平均数量 (quantity) 显示在 averageQuantity 字段中:

{ "_id" : 5, "type" : "strawberry", "orderDate" : ISODate("2019-01-08T06:12:03Z"),
"state" : "WA", "price" : 43, "quantity" : 134, "averageQuantity" : 134 }
{ "_id" : 4, "type" : "strawberry", "orderDate" : ISODate("2019-05-18T16:09:01Z"),
"state" : "CA", "price" : 41, "quantity" : 162, "averageQuantity" : 148 }
{ "_id" : 3, "type" : "vanilla", "orderDate" : ISODate("2020-02-08T13:13:23Z"),
"state" : "WA", "price" : 13, "quantity" : 104, "averageQuantity" : 104 }
{ "_id" : 0, "type" : "chocolate", "orderDate" : ISODate("2020-05-18T14:10:30Z"),
"state" : "CA", "price" : 13, "quantity" : 120, "averageQuantity" : 112 }
{ "_id" : 2, "type" : "vanilla", "orderDate" : ISODate("2021-01-11T06:31:15Z"),
"state" : "CA", "price" : 12, "quantity" : 145, "averageQuantity" : 145 }
{ "_id" : 1, "type" : "chocolate", "orderDate" : ISODate("2021-03-20T11:30:05Z"),
"state" : "WA", "price" : 14, "quantity" : 140, "averageQuantity" : 142.5 }

此示例使用 中的 文档 $setWindowFields窗口输出quantity 中每个$year 的累积和最大蛋糕销量orderDate 值:

db.cakeSales.aggregate( [
{
$setWindowFields: {
partitionBy: { $year: "$orderDate" },
sortBy: { orderDate: 1 },
output: {
cumulativeQuantityForYear: {
$sum: "$quantity",
window: {
documents: [ "unbounded", "current" ]
}
},
maximumQuantityForYear: {
$max: "$quantity",
window: {
documents: [ "unbounded", "unbounded" ]
}
}
}
}
}
] )

在示例中:

  • partitionBy: "$orderDate" 中的$year 对集合中的文档进行orderDate 分区 。2019 2020、 和2021 都有分区。

  • sortBy: { orderDate: 1 }orderDate以升序 ( 1 ) 对每个分区中的文档进行排序,因此最早的orderDate位于最前面。

  • output

    • cumulativeQuantityForYear 字段设置为每年的累积quantity

    • 使用在quantity 文档$sum 窗口中运行的 操作符计算累积 。

      窗口包含介于unbounded下限和current文档之间的文档。这意味着$sum会返回分区开头和当前文档之间的文档的累积数量。

    • maximumQuantityForYear 字段设置为每年的最高量 (quantity)。

    • 使用在quantity 文档$max 窗口中运行的 操作符计算所有文档的最大 。

      窗口包含介于unbounded下限和upper限制之间的文档。这意味着$max会返回分区中文档的最大数量。

在此示例输出中,累计 quantity 显示在 cumulativeQuantityForYear 字段中,最大 quantity 显示在 maximumQuantityForYear 字段中:

{ "_id" : 5, "type" : "strawberry", "orderDate" : ISODate("2019-01-08T06:12:03Z"),
"state" : "WA", "price" : 43, "quantity" : 134,
"cumulativeQuantityForYear" : 134, "maximumQuantityForYear" : 162 }
{ "_id" : 4, "type" : "strawberry", "orderDate" : ISODate("2019-05-18T16:09:01Z"),
"state" : "CA", "price" : 41, "quantity" : 162,
"cumulativeQuantityForYear" : 296, "maximumQuantityForYear" : 162 }
{ "_id" : 3, "type" : "vanilla", "orderDate" : ISODate("2020-02-08T13:13:23Z"),
"state" : "WA", "price" : 13, "quantity" : 104,
"cumulativeQuantityForYear" : 104, "maximumQuantityForYear" : 120 }
{ "_id" : 0, "type" : "chocolate", "orderDate" : ISODate("2020-05-18T14:10:30Z"),
"state" : "CA", "price" : 13, "quantity" : 120,
"cumulativeQuantityForYear" : 224, "maximumQuantityForYear" : 120 }
{ "_id" : 2, "type" : "vanilla", "orderDate" : ISODate("2021-01-11T06:31:15Z"),
"state" : "CA", "price" : 12, "quantity" : 145,
"cumulativeQuantityForYear" : 145, "maximumQuantityForYear" : 145 }
{ "_id" : 1, "type" : "chocolate", "orderDate" : ISODate("2021-03-20T11:30:05Z"),
"state" : "WA", "price" : 14, "quantity" : 140,
"cumulativeQuantityForYear" : 285, "maximumQuantityForYear" : 145 }

此示例使用 $setWindowFieldsquantity10中的 范围 窗口,返回针对当前文档price 值正负 美元内的订单所售蛋糕的 值的总和:

db.cakeSales.aggregate( [
{
$setWindowFields: {
partitionBy: "$state",
sortBy: { price: 1 },
output: {
quantityFromSimilarOrders: {
$sum: "$quantity",
window: {
range: [ -10, 10 ]
}
}
}
}
}
] )

在示例中:

  • partitionBy: "$state"state对集合中的文档进行分区CAWA都有分区。

  • sortBy: { price: 1 }price以升序 ( 1 ) 对每个分区中的文档进行排序,因此最低的price位于最前面。

  • outputquantityFromSimilarOrders字段设置为范围窗口中文档的quantity值的总和。

    • 窗口包含介于下限-10和上限10之间的文档。该范围包含边界值。

    • $sum 返回当前文档的 price 值正负 10 美元范围内包含的 quantity 值的总和。

在此示例输出中,窗口中文档的 quantity 值的总和显示在 quantityFromSimilarOrders 字段中:

{ "_id" : 2, "type" : "vanilla", "orderDate" : ISODate("2021-01-11T06:31:15Z"),
"state" : "CA", "price" : 12, "quantity" : 145, "quantityFromSimilarOrders" : 265 }
{ "_id" : 0, "type" : "chocolate", "orderDate" : ISODate("2020-05-18T14:10:30Z"),
"state" : "CA", "price" : 13, "quantity" : 120, "quantityFromSimilarOrders" : 265 }
{ "_id" : 4, "type" : "strawberry", "orderDate" : ISODate("2019-05-18T16:09:01Z"),
"state" : "CA", "price" : 41, "quantity" : 162, "quantityFromSimilarOrders" : 162 }
{ "_id" : 3, "type" : "vanilla", "orderDate" : ISODate("2020-02-08T13:13:23Z"),
"state" : "WA", "price" : 13, "quantity" : 104, "quantityFromSimilarOrders" : 244 }
{ "_id" : 1, "type" : "chocolate", "orderDate" : ISODate("2021-03-20T11:30:05Z"),
"state" : "WA", "price" : 14, "quantity" : 140, "quantityFromSimilarOrders" : 244 }
{ "_id" : 5, "type" : "strawberry", "orderDate" : ISODate("2019-01-08T06:12:03Z"),
"state" : "WA", "price" : 43, "quantity" : 134, "quantityFromSimilarOrders" : 134 }

以下示例使用的窗口的时间范围上限单位$setWindowFields为正。管道输出与指定时间范围匹配的每个stateorderDate值的数组。

db.cakeSales.aggregate( [
{
$setWindowFields: {
partitionBy: "$state",
sortBy: { orderDate: 1 },
output: {
recentOrders: {
$push: "$orderDate",
window: {
range: [ "unbounded", 10 ],
unit: "month"
}
}
}
}
}
] )

在示例中:

  • partitionBy: "$state"state对集合中的文档进行分区CAWA都有分区。

  • sortBy: { orderDate: 1 }orderDate以升序 ( 1 ) 对每个分区中的文档进行排序,因此最早的orderDate位于最前面。

  • output

    • 将各 state 文档中的 orderDateArrayForState 数组字段设置为 orderDate 值。数组元素通过添加数组中的前一个元素进行扩展。

    • 使用$push范围窗口中的文档返回orderDate值的数组。

  • 窗口包含介于unbounded下限和上限设置为10 (当前文档的orderDate值晚10个月)之间的文档(使用时间范围单位)。

  • $push 返回分区起始和满足如下条件的文档之间文档的 orderDate 值的数组:orderDate 值在当前文档的 orderDate 值(含)加上 10 10 个月范围内。

在此示例输出中,CAWAorderDate 值数组显示在 recentOrders 字段中:

{ "_id" : 4, "type" : "strawberry", "orderDate" : ISODate("2019-05-18T16:09:01Z"),
"state" : "CA", "price" : 41, "quantity" : 162,
"recentOrders" : [ ISODate("2019-05-18T16:09:01Z") ] }
{ "_id" : 0, "type" : "chocolate", "orderDate" : ISODate("2020-05-18T14:10:30Z"),
"state" : "CA", "price" : 13, "quantity" : 120,
"recentOrders" : [ ISODate("2019-05-18T16:09:01Z"), ISODate("2020-05-18T14:10:30Z"), ISODate("2021-01-11T06:31:15Z") ] }
{ "_id" : 2, "type" : "vanilla", "orderDate" : ISODate("2021-01-11T06:31:15Z"),
"state" : "CA", "price" : 12, "quantity" : 145,
"recentOrders" : [ ISODate("2019-05-18T16:09:01Z"), ISODate("2020-05-18T14:10:30Z"), ISODate("2021-01-11T06:31:15Z") ] }
{ "_id" : 5, "type" : "strawberry", "orderDate" : ISODate("2019-01-08T06:12:03Z"),
"state" : "WA", "price" : 43, "quantity" : 134,
"recentOrders" : [ ISODate("2019-01-08T06:12:03Z") ] }
{ "_id" : 3, "type" : "vanilla", "orderDate" : ISODate("2020-02-08T13:13:23Z"),
"state" : "WA", "price" : 13, "quantity" : 104,
"recentOrders" : [ ISODate("2019-01-08T06:12:03Z"), ISODate("2020-02-08T13:13:23Z") ] }
{ "_id" : 1, "type" : "chocolate", "orderDate" : ISODate("2021-03-20T11:30:05Z"),
"state" : "WA", "price" : 14, "quantity" : 140,
"recentOrders" : [ ISODate("2019-01-08T06:12:03Z"), ISODate("2020-02-08T13:13:23Z"), ISODate("2021-03-20T11:30:05Z") ] }

以下示例使用的窗口的时间范围上限单位为负,单位$setWindowFields 。管道输出与指定时间范围匹配的每个stateorderDate值的数组。

db.cakeSales.aggregate( [
{
$setWindowFields: {
partitionBy: "$state",
sortBy: { orderDate: 1 },
output: {
recentOrders: {
$push: "$orderDate",
window: {
range: [ "unbounded", -10 ],
unit: "month"
}
}
}
}
}
] )

在示例中:

  • partitionBy: "$state"state对集合中的文档进行分区CAWA都有分区。

  • sortBy: { orderDate: 1 }orderDate以升序 ( 1 ) 对每个分区中的文档进行排序,因此最早的orderDate位于最前面。

  • output

    • 将各 state 文档中的 orderDateArrayForState 数组字段设置为 orderDate 值。数组元素通过添加数组中的前一个元素进行扩展。

    • 使用$push范围窗口中的文档返回orderDate值的数组。

  • 窗口包含介于unbounded下限和上限设置为-10 (当前文档的orderDate值之前10个月)之间的文档(使用时间范围单位)。

  • $push 返回分区起始和满足如下条件的文档之间文档的 orderDate 值的数组:orderDate 值在当前文档的 orderDate 值(含)减去 10 10 个月范围内。

在此示例输出中,CAWAorderDate 值数组显示在 recentOrders 字段中:

{ "_id" : 4, "type" : "strawberry", "orderDate" : ISODate("2019-05-18T16:09:01Z"),
"state" : "CA", "price" : 41, "quantity" : 162,
"recentOrders" : [ ] }
{ "_id" : 0, "type" : "chocolate", "orderDate" : ISODate("2020-05-18T14:10:30Z"),
"state" : "CA", "price" : 13, "quantity" : 120,
"recentOrders" : [ ISODate("2019-05-18T16:09:01Z") ] }
{ "_id" : 2, "type" : "vanilla", "orderDate" : ISODate("2021-01-11T06:31:15Z"),
"state" : "CA", "price" : 12, "quantity" : 145,
"recentOrders" : [ ISODate("2019-05-18T16:09:01Z") ] }
{ "_id" : 5, "type" : "strawberry", "orderDate" : ISODate("2019-01-08T06:12:03Z"),
"state" : "WA", "price" : 43, "quantity" : 134,
"recentOrders" : [ ] }
{ "_id" : 3, "type" : "vanilla", "orderDate" : ISODate("2020-02-08T13:13:23Z"),
"state" : "WA", "price" : 13, "quantity" : 104,
"recentOrders" : [ ISODate("2019-01-08T06:12:03Z") ] }
{ "_id" : 1, "type" : "chocolate", "orderDate" : ISODate("2021-03-20T11:30:05Z"),
"state" : "WA", "price" : 14, "quantity" : 140,
"recentOrders" : [ ISODate("2019-01-08T06:12:03Z"), ISODate("2020-02-08T13:13:23Z") ] }

提示

另请参阅:

有关 IOT 功耗的其他示例,请参阅 Practical MongoDB Aggregations 电子书。

← $set(聚合)