Skip to content

Instantly share code, notes, and snippets.

@zhangchiqing
Last active February 18, 2016 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangchiqing/15b6e149f05cf54c8eb0 to your computer and use it in GitHub Desktop.
Save zhangchiqing/15b6e149f05cf54c8eb0 to your computer and use it in GitHub Desktop.
mongdb_distinct_count.js
db.COLLECTION_NAME.aggregate([
{ $match: { created_at: { $gte: ISODate("2016-02-05T00:00:00.000Z"), $lt: ISODate("2016-02-06T00:00:00.000Z") } } },
{ $group: { _id: '$FIELD_NAME', count: { $sum: 1 } } },
{ $sort: { count: -1 } }
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment