I have data like this,
{
meta: {
artist: "artist",
album: "album",
year: 2008
}
}
and I want to do the equivilent of an SQL group by on the artist to produce a list of objects with { album: album, year: year }
using mongodb aggregation.
I have this query which is almost what I want but I dont think its the correct way of doing it.
db.pending.aggregate( [
{ $project:
{ 'meta.artist': 1, 'meta.album': 1, 'meta.year':1 }
},
{ $group:
{
'_id':
{ artist: '$meta.artist', album: '$meta.album',
year: { $year: '$meta.year'}
}
}
}
] )