Created
November 8, 2013 07:54
-
-
Save dancrew32/7367657 to your computer and use it in GitHub Desktop.
Mongo distinct keys map reduce
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
var collection = "your_collection" | |
var distinct_keys_map_reduce = db.runCommand({ | |
"mapreduce" : collection, | |
"map" : function() { | |
for (var key in this) { emit(key, null); } | |
}, | |
"reduce" : function(key, val) { return null; }, | |
"out": collection + "_keys" | |
}) | |
db[distinct_keys_map_reduce.keys].distinct("_id") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment