Hi all, I have a collection in a mongodb database which has the form
{
"_id" : ObjectId("57bffb4763e3de564a9f230d"),
"id" : 29942,
"title" : "01 Ain't talkin about love",
"genre" : "Classic Rock",
"artist" : "NBPM",
"album" : "New Band Practice Material",
"duration" : 231.933
}
What I would like to produce is a listing grouped by artist and then album.
The following produces a list grouped by album
db.tracks.aggregate( [ { $group : { _id : "$album",tracks:{$push:'$title' } }} ] )
{
"result" : [
{
"_id" : "The Hissing Of Summer Lawns",
"tracks" : [
"The Boho Dance",
"Don't Interrupt The Sorrow",
"Edith And The Kingpin",
"Harry's House-Centerpiece",
"The Hissing Of Summer Lawns",
"In France They Kiss On Main Street",
"The Jungle Line",
"Shades Of Scarlett Conquering",
"Shadows And Light",
"Sweet Bird"
]
},
{
"_id" : "Shine",
"tracks" : [
"Bad Dreams",
"Big Yellow Taxi (2007)",
"Hana",
"If",
"If I Had A Heart",
"Night Of The Iguana",
"One Week Last Summer",
"Shine",
"Strong And Wrong",
"This Place"
]
},
{
"_id" : "Hejira",
"tracks" : [
"Amelia",
"A Strange Boy",
"Black Crow",
"Blue Motel Room",
"Coyote",
"Furry Sings the Blues",
"Hejira",
"Refuge of the Roads",
"Song for Sharon"
]
},
{
"_id" : "Blue",
"tracks" : [
"A Case of You",
"All I Want",
"Blue",
"California",
"Carey",
"The Last Time I Saw Richard",
"Little Green",
"My Old Man",
"River",
"This Flight Tonight"
]
}
]
}
so I just need help with the final step to group by artist
What I have tried:
Everything shown in my code and googling