/* The websites that have some MRI detected AND which are either in NZ or with NZ TLD or (so if they're from overseas) don't contain /mi or mi.* in URL path. We'll include Australia, to get the valid "kiwiproperty.com" website, otherwise the sole exception, included in the result list. db.getCollection('Websites').find({$and: [ {numPagesContainingMRI: {$gt: 0}}, {$or: [{geoLocationCountryCode: /(NZ|AU)/}, {domain: /\.nz$/}, {urlContainsLangCodeInPath: false}]} ]}).count() 397 Aggregate results by a count of country codes: db.Websites.aggregate([ { $match: { $and: [ {numPagesContainingMRI: {$gt: 0}}, {$or: [{geoLocationCountryCode: /(NZ|AU)/}, {domain: /\.nz$/}, {urlContainsLangCodeInPath: false}]} ] } }, { $unwind: "$geoLocationCountryCode" }, { $group: { _id: {$toLower: '$geoLocationCountryCode'}, count: { $sum: 1 } } }, { $sort : { count : -1} } ]); */ /* 1 */ { "_id" : "us", "count" : 181.0 } /* 2 */ { "_id" : "nz", "count" : 89.0 } /* 3 */ { "_id" : "au", "count" : 21.0 } /* 4 */ { "_id" : "de", "count" : 19.0 } /* 5 */ { "_id" : "fr", "count" : 17.0 } /* 6 */ { "_id" : "nl", "count" : 16.0 } /* 7 */ { "_id" : "dk", "count" : 8.0 } /* 8 */ { "_id" : "ca", "count" : 7.0 } /* 9 */ { "_id" : "es", "count" : 6.0 } /* 10 */ { "_id" : "gb", "count" : 5.0 } /* 11 */ { "_id" : "cz", "count" : 4.0 } /* 12 */ { "_id" : "at", "count" : 3.0 } /* 13 */ { "_id" : "it", "count" : 3.0 } /* 14 */ { "_id" : "ro", "count" : 3.0 } /* 15 */ { "_id" : "il", "count" : 2.0 } /* 16 */ { "_id" : "ch", "count" : 2.0 } /* 17 */ { "_id" : "bg", "count" : 1.0 } /* 18 */ { "_id" : "sg", "count" : 1.0 } /* 19 */ { "_id" : "mx", "count" : 1.0 } /* 20 */ { "_id" : "ir", "count" : 1.0 } /* 21 */ { "_id" : "cn", "count" : 1.0 } /* 22 */ { "_id" : "ie", "count" : 1.0 } /* 23 */ { "_id" : "jp", "count" : 1.0 } /* 24 */ { "_id" : "fi", "count" : 1.0 } /* 25 */ { "_id" : "gr", "count" : 1.0 } /* 26 */ { "_id" : "ru", "count" : 1.0 } /* 27 */ { "_id" : "unknown", "count" : 1.0 }