小编vkl*_*ein的帖子

Spring Boot MongoDB 聚合与 ReplaceRoot/如何获取组中的最新项目

我想在 Spring Boot 应用程序中获取此 MongoDB 查询的结果。

db.getCollection('contentSource').aggregate( [ { $sort: { "modified": -1 } }, 
{ $group: { _id: "$sourceId", cs: { $push: "$$ROOT" } }}, 
{ $replaceRoot: { newRoot: { $arrayElemAt: ['$cs', 0] } }} ] )
Run Code Online (Sandbox Code Playgroud)

有谁知道如何将 replaceRoot 添加到我的聚合中?

spring aggregation mongodb

5
推荐指数
1
解决办法
1570
查看次数

标签 统计

aggregation ×1

mongodb ×1

spring ×1