Reputation: 8631
I am trying to recreate this query on spring mongo layer.
db.LASTVIEWED_TEST.aggregate([{$match: {'_id' : '12070'}},
{$unwind:"$value"},
{$match:{"value.Dockey":{"$in":["390", "539","626"]}}},
{$group:{_id:"$_id", "value":{$push:"$value"}}}
])
I have made some attempts using various methods however I came across the examples here:
and created this:
Aggregation agg = Aggregation.newAggregation(//
match(where("entityid").is(entityId)),//
unwind("$value"), //
match(where("value.Dockey").in(dockeyList)),//
group("id").push("$value").as("value")//
);
However this builder does not see to recognise the where, unwind keywords etc... and my compiler tells me my class does not have these methods.
What do I need to do to pass values to the newAggregation builder.
cheers,
Upvotes: 1
Views: 1015
Reputation: 151092
You need to specify a Criteria
object in the match, and generally all values are just represented as strings:
Aggregation agg = newAggregation(
match(Criteria.where("entityid").is(entityId)),
unwind("value"),
match(Criteria.where("value.Dockey").in(dockeyList)),
group("_id").push("value").as("value")
);
Upvotes: 1