db = db.getSiblingDB("whyd_music") // explicitely select collection var jan2014 = ObjectId("52c35a800000000000000000"); // created using http://steveridout.github.io/mongo-object-time/ db.post.aggregate([ {"$sort": {"_id": -1}}, // order: antichronological {"$match": {"_id": {"$gt": jan2014}}}, // only documents that were created after the 1syt january 2014 {"$group": {"_id": "$eId", // group by value of the eId attribute -> _id attribute in the resulting output collection "name": {"$first": "$name"}, // -> include the name of each grouped category "count": {"$sum": 1}}}, // -> count attribute will contain the number of documents for each value of _eid {"$match": {"count": {"$gt": 50}}}, // limit output to results with count > 50 {"$sort": {"count": -1}} // output order: highest count first ]).forEach(function(f){print(tojson(f, '', true));}); // avoids mongoshell's paging