首页 > 解决方案 > Spring MongoDB AggregationOperation 获取文档ID

问题描述

我正在尝试在 Mongodb 聚合操作期间获取对文档 ID 的引用

代码如下

Aggregation aggregation = newAggregation(
        (AggregationOperationContext aoc) -> {
                System.out.println(aoc.getReference("$_id").getReferenceValue());
                return new Document("$set", new Document("field", "1"));
        }
);

运行此代码仅打印出数字 1

我试过而不是$_id只是idand _id,同样的结果

标签: springmongodbspring-bootaggregation-framework

解决方案


推荐阅读