MongoDB Get names of all keys in collection -


i'd names of keys in mongodb collection.

for example, this:

db.things.insert( { type : ['dog', 'cat'] } ); db.things.insert( { egg : ['cat'] } ); db.things.insert( { type : [] } ); db.things.insert( { hello : []  } ); 

i'd unique keys:

type, egg, hello 

you mapreduce:

mr = db.runcommand({   "mapreduce" : "my_collection",   "map" : function() {     (var key in this) { emit(key, null); }   },   "reduce" : function(key, stuff) { return null; },    "out": "my_collection" + "_keys" }) 

then run distinct on resulting collection find keys:

db[mr.result].distinct("_id") ["foo", "bar", "baz", "_id", ...] 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -