Skip to content

Instantly share code, notes, and snippets.

@arthuralvim
Created February 21, 2017 19:55
Show Gist options
  • Save arthuralvim/022c0ab60a05c948404787f8efa6f387 to your computer and use it in GitHub Desktop.
Save arthuralvim/022c0ab60a05c948404787f8efa6f387 to your computer and use it in GitHub Desktop.
Get all keys for a MongoDB collection.
mr = db.runCommand({
"mapreduce" : "extracao_unimed",
"map" : function() {
for (var key in this) { emit(key, null); }
},
"reduce" : function(key, stuff) { return null; },
"out": "extracao_unimed" + "_keys"
})
db[mr.result].distinct("_id")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment