我想在 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 添加到我的聚合中?