Click here to Skip to main content
15,888,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
pkfox 29-Aug-16 9:54am    
Hi there and thanks but that doesn't really help me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900