Created
July 15, 2016 14:46
-
-
Save jnm/d445a3f87bba3fb30aa4a5aa5c10cbed to your computer and use it in GitHub Desktop.
Get all the keys from all documents in a Mongo collection
This file contains hidden or 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
// mapReduce idea credit: http://stackoverflow.com/a/2308036 | |
db.instances.mapReduce( | |
function() { | |
// map | |
for(var key in this) { | |
emit(key, null); | |
} | |
}, | |
function(key, values) { | |
// reduce | |
return null; | |
}, | |
{out: {inline: 1}} | |
).results.map(function(value) { | |
// results are `_id`, `value` pairs, where `value` is always `null` | |
return value._id; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment