Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. db.myDb.aggregate(
  2. {
  3. $group:{
  4. _id: {
  5. class_name : "$class",
  6. type_name : "$name"
  7. },
  8. items: {
  9. $addToSet : "$name"
  10. }
  11. }
  12. },
  13. {
  14. $group:{
  15. _id : "$_id.class_name",
  16. types : {
  17. $addToSet : {
  18. type : "$_id.type_name",
  19. items : "$items"
  20. }
  21. }
  22. }
  23. })
  24.  
  25. {
  26. _id : "class A",
  27. types: [
  28. {
  29. type: "type 1",
  30. items: ["ObjectA1"]
  31. },
  32. {
  33. type: "type 2",
  34. items: ["ObjectA2_1", "ObjectA2_2"]
  35. }
  36. ]
  37. },
  38. {
  39. _id : "class B",
  40. types: [
  41. {
  42. type: "type 3",
  43. items: ["ObjectB3"]
  44. }
  45. ]
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement