MongoDB Get names of all keys in collection

  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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 把蟑螂打死,她就不害怕了。人总是要从击败和伤害中找到自豪感和安全感。 (1) 周迅在电视上用不男不女的声音无辜地说...
    定君阅读 401评论 3 1
  • 2017,我给自己列了很多愿望清单,当然升职加薪是第一位的。很多人觉得我离开上一家公司很突然,其实不然。我经历了很...
    木子Scorpio阅读 261评论 0 1
  • 凭高舒望眼 天远黯云低 倚牖长风阔 兴阑两相宜
    五绝肥人阅读 135评论 0 0