【问题标题】:Spring Mongo aggregation query with concatenating two arrays and project the resultSpring Mongo 聚合查询,连接两个数组并投影结果
【发布时间】:2018-03-17 00:16:01
【问题描述】:

我有一个 MongoDB 聚合查询,我需要 Spring boot mongo 聚合对象示例用于以下查询。

db.case.aggregate([ 
  { $project: { item: { $concatArrays: [ "$workApproval.partItems", "$warrantyClaims.items.items" ] } } }
  ,{ $unwind : "$item"} 
])  

我卡在 concatArray 部分,我不知道如何在 Spring Boot Mongo 聚合中编写上述查询,感谢任何帮助。

【问题讨论】:

    标签: mongodb spring-boot aggregation-framework spring-mongo


    【解决方案1】:

    你在这里:

    List<AggregationOperation> operations = new ArrayList<>();
    operations.add(
                Aggregation.project()
                        .and("workApproval.partItems").concatArrays("warrantyClaims.items.items").as("item")
        );
    operations.add(Aggregation.unwind("item"));
    Aggregation aggregation = Aggregation.newAggregation(operations);
    

    【讨论】:

    • 非常感谢您的帮助,非常感谢。
    猜你喜欢
    • 1970-01-01
    • 2019-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 2014-02-23
    相关资源
    最近更新 更多