Last active
July 18, 2017 06:42
-
-
Save xexi/a922bb7e4d7c766582cf41e5a927386b to your computer and use it in GitHub Desktop.
mongo_shell_distinct
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
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