Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- db.myDb.aggregate(
- {
- $group:{
- _id: {
- class_name : "$class",
- type_name : "$name"
- },
- items: {
- $addToSet : "$name"
- }
- }
- },
- {
- $group:{
- _id : "$_id.class_name",
- types : {
- $addToSet : {
- type : "$_id.type_name",
- items : "$items"
- }
- }
- }
- })
- {
- _id : "class A",
- types: [
- {
- type: "type 1",
- items: ["ObjectA1"]
- },
- {
- type: "type 2",
- items: ["ObjectA2_1", "ObjectA2_2"]
- }
- ]
- },
- {
- _id : "class B",
- types: [
- {
- type: "type 3",
- items: ["ObjectB3"]
- }
- ]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement