MongoDB Get names of all keys in

2017-08-30  本文已影响64人  LucasX
  1. You could do this with MapReduce:
    mr = db.runCommand({
    "mapreduce" : "my_collection",
    "map" : function() {
    for (var key in this) { emit(key, null); }
    },
    "reduce" : function(key, stuff) { return null; },
    "out": "my_collection" + "_keys"
    })

Then run distinct on the resulting collection so as to find all the keys:
db[mr.result].distinct("_id")

["foo", "bar", "baz", "_id", ...]

  1. Try this tool: https://github.com/variety/variety.git
上一篇下一篇

猜你喜欢

热点阅读