Skip to content

Instantly share code, notes, and snippets.

@StoneMoe
Created August 3, 2016 14:56
Show Gist options
  • Save StoneMoe/2d6302a324e104e12bd3ee43c0e8cc04 to your computer and use it in GitHub Desktop.
Save StoneMoe/2d6302a324e104e12bd3ee43c0e8cc04 to your computer and use it in GitHub Desktop.
Mongodb manage commands gist
# Mongodb get collection key names
mr = db.runCommand({
"mapreduce" : "input_collection_name_here",
"map" : function() {
for (var key in this) { emit(key, null); }
},
"reduce" : function(key, stuff) { return null; },
"out": "input_collection_name_here" + "_keys"
});
db[mr.result].distinct("_id");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment