Created
November 3, 2017 20:25
-
-
Save danielskapunk/257d03c000e2c08f48cfec9b56be8633 to your computer and use it in GitHub Desktop.
Mongo Group Aggregate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //GROUP BY WORKSHOP ID | |
| db.getCollection('enrolments').aggregate([{ | |
| $group: | |
| { | |
| _id: {workshopId: "$workshopId"}, | |
| contacts: { $push: {contactId: '$contactId'} } | |
| } | |
| }]) | |
| GROUP FIRST BY WEEKDAY AND WORKSHOP THEN BY WEEKDAY | |
| db.getCollection('enrolments').aggregate([ | |
| { $unwind: '$attendances' }, | |
| { | |
| $group: | |
| { | |
| _id: {weekDay: "$attendances.weekDay", workshopId:"$workshopId"}, | |
| contacts: { $push: {contactId: '$contactId', day: "$attendances.day", status:'$attendances.status'} } | |
| } | |
| }, | |
| { | |
| $group: | |
| { | |
| _id: {weekDay: "$_id.weekDay"}, | |
| workshops: { $push: {workshopId:'$_id.workshopId', contacts: '$contacts'} } | |
| } | |
| } | |
| ]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment