followings will list all fields exist in a collection in mongodb :
Pymongo:
Mongodb Shell:
Pymongo:
#Using pymongo and connection named 'db'
reduce(
lambda all_keys, rec_keys: all_keys | set(rec_keys),
map(lambda d: d.keys(), db.things.find()),
set()
)
Mongodb Shell:
mr = db.runCommand(
{"mapreduce" : "temp",
"map" : function() {
for (var key in this) { emit(key, null); }
},
"reduce" : function(key, stuff) { return null; },
"out": "temp" + "_keys"
})
db[mr.result].distinct("_id")
No comments:
Post a Comment