I have a MongoDB and I want to query the database on some values and add them together where a condition matches.
Here is my Collection entry:
{
"_id" : ObjectId("5875ed1dc939408da0601f31"),
"AlbumName" : "Blurryface",
"Group" : "21 Pilots",
"Date" : "20151110",
"Label" : "Fueled By Ramen",
"Writers" : "Tyler Joseph",
"Producer" : "Mike Elizondo",
"Songlist" : [
{
"_id" : ObjectId("5875e5e8c939408da0601d73"),
"SongID" : "1",
"SongName" : "Stressed Out",
"Artist" : "21 Pilots",
"Duration:" : "200",
"nPlays" : "800000000",
"SongDataFile" : "data"
}
]
}
I match AlbumName and want to get the nPlays for all(if there are more) songs in "Songlist"
db.Albums.aggregate([
{$match: {AlbumName: 'Blurryface'}},
{$unwind: '$Songlist'},
])
However now I can't find out how I get the nPlays from the songs in the array and how I can use them for other things.
How do I get nPlays with MongoDB aggregation?