Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- db.articles.aggregate([
- {"$unwind": "$tags"},
- {
- "$lookup": {
- "localField": "tags",
- "from": "tags",
- "foreignField": "_id",
- "as": "materialTags"
- }
- },
- {
- "$group": {
- "_id": "$_id",
- "title": {"$first": "$title"},
- "materialTags": {"$push": "$materialTags"}
- }
- }
- ])
- UnwindOperation unwindOperation = Aggregation.unwind("tags");
- LookupOperation lookupOperation1 = LookupOperation.newLookup()
- .from("tags")
- .localField("tags")
- .foreignField("_id")
- .as("materialTags");
- //I also want to add group operation but unable to find the proper syntax ??.
- Aggregation aggregation = Aggregation.newAggregation(unwindOperation,
- lookupOperation1, ??groupOperation?? );
- AggregationResults<Article> resultList
- = mongoTemplate.aggregate(aggregation, "articles", Article.class);
Add Comment
Please, Sign In to add comment