The Problem: I currently have a list of documents that I would like to group by the attribute 'eventType'. The document (representing a song) currently look like this:
Song Document:
{
id: ID,
eventType: String,
numberOfLikes: Integer,
sections: String[]
}
Result: I would like to have these grouped by eventType, like as follows:
eventType: {
songs: [{
songId: ID,
numberOfLikes: Integer,
sections: String[]
}]
}
How would I do this using the MongoDB aggregation pipeline? I am using MongoDB 4.4.