Skip to content

Instantly share code, notes, and snippets.

@xexi
Last active July 18, 2017 06:42
Show Gist options
  • Save xexi/a922bb7e4d7c766582cf41e5a927386b to your computer and use it in GitHub Desktop.
Save xexi/a922bb7e4d7c766582cf41e5a927386b to your computer and use it in GitHub Desktop.
mongo_shell_distinct
db.collection.aggregate( [
{ $match: { 'dept': "service", 'condition': '0' } },
{ $group: { _id: { first: "$distinct_col1", second: "$distinct_col1" }, // distinct option
id_tag : { $min: "$tag" }, // projection
count: { $sum:1 } // group count
}
},
{ $sort: { '_.id.regdate': 1 }}, // make sure sort by group id // 1 asc
{ $skip: 0 },
{ $limit: 5 },
], { "allowDiskUse" : true }); // if memory problem occured
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment