Skip to content

Instantly share code, notes, and snippets.

@anscii
Last active December 30, 2015 05:59
Show Gist options
  • Save anscii/7786087 to your computer and use it in GitHub Desktop.
Save anscii/7786087 to your computer and use it in GitHub Desktop.
Count mongo subarrays with filter by _id and subarray type
myres = db.tag_ru.aggregate(
{ $match: {_id: 1354987}},
{ $unwind: '$items'},
{ $match: {'items.type': "news"}},
{ $group: {_id: '$_id', items: {$sum: '$items'}}})
myres.result[0].items.length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment