【发布时间】:2019-04-15 03:23:24
【问题描述】:
我在 StackOverFlow 上找到了几个与聚合中的 addFields 相关的示例。 但是没有人用 Java 实现。
db.getCollection('myDocument').aggregate([
{$match : {"metaId.ref.uuid" : "d6112808-1ce1-4545-bd52-cf55bc4ed25e"}},
{$lookup: {from: "simple", localField: "someId.ref.uuid", foreignField: "uuid",
as: "simple"}},
{"$unwind": "$simple"},
{"$addFields": { "metaId.ref.name" : "$simple.name" }}
])
我无法在 Java 中正确实现:-- 没有得到正确的程序
LookupOperation lookupOperation =LookupOperation.newLookup().from("simple").localField("execId.ref.uuid").foreignField("uuid").as("simple");
Aggregation myDocAggr = newAggregation(match(Criteria.where("metaId.ref.uuid").is(someUUID)), group("uuid").max("version").as("version"),
lookupOperation,
Aggregates.unwind(""),
Aggregates.addFields(fields));
Document document =new Document();
AggregationResults<String> myDocAggrResults = mongoTemplate.aggregate(myDocAggr , myDocument, myDocument.class);
List<String> mydocumentList = myDocAggrResults .getMappedResults();
无法使用 unwind 和 addFields,这是示例 java 代码,但不行。 请帮我。在此先感谢
【问题讨论】:
-
哪个错误/堆栈跟踪?
-
编译错误是什么意思?
-
我猜至少缺少一个右括号
-
Aggregates.unwind(""),之后应该有一些右括号?你想为方法调用提供什么参数? -
您尝试调用哪个
newAggregation方法?
标签: java mongodb mongodb-query aggregation-framework spring-data-mongodb