kanchan
kanchan

Reputation: 167

Spring Mongo aggregation query with concatenating two arrays and project the result

I have a MongoDB aggregation query, I need the Spring boot mongo aggregation object example for the Following query.

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

I am stuck on the concatArray portion, I am not sure how to write the above query in Spring Boot Mongo aggregation, any help is appreciated.

Upvotes: 1

Views: 2810

Answers (1)

barbakini
barbakini

Reputation: 3144

Here you are:

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);

Upvotes: 3

Related Questions