Skip to content

Instantly share code, notes, and snippets.

@anscii
Last active December 31, 2015 20:29
Show Gist options
  • Save anscii/8040820 to your computer and use it in GitHub Desktop.
Save anscii/8040820 to your computer and use it in GitHub Desktop.
Count mongo subarrays with subarray field matching for all possible _ids
db.tag_ru.aggregate({ $unwind: '$items'}, { $match: { "items.type":"news"}}, { $group: {_id: '$_id', count: {$sum: 1}}}, {$group: {_id:null, cnt:{$sum:"$count"} } } )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment