spring数据聚合查询

vcirk6k6  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(211)

我很难将纯json查询Map到它的spring数据表示:

db.getCollection('taxon').aggregate( 
  [
    { $match: { "value.id": "someId123" } },
    {
      $graphLookup: {
        from: "taxon",
        startWith: "$value.id",
        connectFromField: "value.id",
        connectToField: "value.parentId",
        as: "children"}
    },
    { $project : { "children.value.unterwarengruppenIds" : 1 } },
    { $unwind: "$children"},
    { $unwind: "$children.value.unterwarengruppenIds"},
    { $replaceRoot: { newRoot: "$children.value" } } 
  ] 
)

我已经试过了,但是很明显,我的投影不起作用:

Aggregation aggregation = Aggregation.newAggregation(
  Aggregation.match(Criteria.where("value.id").is(taxon.getId().getValue())),
  Aggregation.graphLookup(COLLECTION_NAME)
    .startWith("$value.id")
    .connectFrom("value.id")
    .connectTo("value.parentId")
    .as("children"),
  Aggregation.project().<NOT SURE HOW TO THIS HERE>,
  Aggregation.unwind("children"),
  Aggregation.unwind("children.value.unterwarengruppenIds"),
  Aggregation.replaceRoot("children.value")
}.withOptions((Aggregation.newAggregationOptions().allowDiskUse(true)
.build()));

我确实花了一些时间,但不知道如何简单地投影嵌套字段。我能把这个画出来吗 $project : { "children.value.unterwarengruppenIds" : 1 } 到spring数据表示?感谢您的帮助:)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题