Last active
December 30, 2015 05:59
-
-
Save anscii/7786087 to your computer and use it in GitHub Desktop.
Count mongo subarrays with filter by _id and subarray type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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