我试图在spring数据mongoDB中强制执行此查询:
descendants
但是,delete []array;
列表不包含50 minutes
1 hour 40 minutes
1 day 2 hours 20 minutes
字段。 javascript查询在mongo shell中完美运行。
我做错了什么?
答案 0 :(得分:1)
TypedAggregation是一个包含信息的特殊聚合 输入聚合类型。
public void graphLookupShouldBeAppliedCorrectly() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_FOUR));
Employee em1 = Employee.builder().id(1).name("Dev").build();
Employee em2 = Employee.builder().id(2).name("Eliot").reportsTo("Dev").build();
Employee em4 = Employee.builder().id(4).name("Andrew").reportsTo("Eliot").build();
mongoTemplate.insert(Arrays.asList(em1, em2, em4), Employee.class);
TypedAggregation<Employee> agg = Aggregation.newAggregation(Employee.class,
match(Criteria.where("name").is("Andrew")), //
Aggregation.graphLookup("employee") //
.startWith("reportsTo") //
.connectFrom("reportsTo") //
.connectTo("name") //
.depthField("depth") //
.maxDepth(5) //
.as("reportingHierarchy"));
AggregationResults<Document> result = mongoTemplate.aggregate(agg, Document.class);
Document object = result.getUniqueMappedResult();
List<Object> list = (List<Object>) object.get("reportingHierarchy");
assertThat(object, isBsonObject().containing("reportingHierarchy", List.class));
assertThat((Document) list.get(0), isBsonObject().containing("name", "Dev").containing("depth", 1L));
assertThat((Document) list.get(1), isBsonObject().containing("name", "Eliot").containing("depth", 0L));
}