美文网首页
MongoDB Get names of all keys in

MongoDB Get names of all keys in

作者: LucasX | 来源:发表于2017-08-30 13:17 被阅读64次
    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

    相关文章

      网友评论

          本文标题:MongoDB Get names of all keys in

          本文链接:https://www.haomeiwen.com/subject/cfhtjxtx.html