Guest User

Untitled

a guest
Oct 23rd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. db.articles.aggregate([
  2. {"$unwind": "$tags"},
  3. {
  4. "$lookup": {
  5. "localField": "tags",
  6. "from": "tags",
  7. "foreignField": "_id",
  8. "as": "materialTags"
  9. }
  10. },
  11. {
  12. "$group": {
  13. "_id": "$_id",
  14. "title": {"$first": "$title"},
  15. "materialTags": {"$push": "$materialTags"}
  16. }
  17. }
  18. ])
  19.  
  20. UnwindOperation unwindOperation = Aggregation.unwind("tags");
  21. LookupOperation lookupOperation1 = LookupOperation.newLookup()
  22. .from("tags")
  23. .localField("tags")
  24. .foreignField("_id")
  25. .as("materialTags");
  26.  
  27. //I also want to add group operation but unable to find the proper syntax ??.
  28. Aggregation aggregation = Aggregation.newAggregation(unwindOperation,
  29. lookupOperation1, ??groupOperation?? );
  30. AggregationResults<Article> resultList
  31. = mongoTemplate.aggregate(aggregation, "articles", Article.class);
Add Comment
Please, Sign In to add comment