在 mongodb 中访问字段名作为元数据
我在 mongo 集合中有许多不同的文档。 属性都是数值。我先验不知道字段名是什么(我知道,但它们可能因文档而异)。
我想编写一个程序,
a)获取集合中的所有唯一字段名 b) 查找集合中每个字段的最大值和最小值
,然后以包含“字段名、最大值、最小值”行的表格形式或等效的 JSON 格式报告。我正在使用 pymongo,但我不必这样做,ruby 或 js 甚至 java 驱动程序都可以。
如何以编程方式访问集合中唯一字段名的列表?那是 主要问题。剩下的我可以处理。
I have a number of different documents in a mongo collection.
The attrs are all numeric values. I don't know apriori what the fieldnames are (I do but they can vary from doc to doc).
I want to write a program that
a) gets all the unique fieldnames in a collection
b) finds the max and min value of each field in the collection
and then reports it in a tabular form with rows "fieldname, maxvalue, minvalue" or in JSON that is equivalent. I am using pymongo but I don't have to, ruby or js or even java driver is fine.
How do I get programmatic access to the list of unique fieldnames in a collection? That's
the major question. I can manage the rest.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要么您将应用程序中使用过的密钥列表作为应用程序逻辑的一部分,保存在同一集合或元集合中的某个文档中,要么您必须迭代所有文档以找出密钥列表...有MongoDB 中没有任何东西可以帮助您,因为 MongoDB 是无模式的。
Either you main the list of used key inside your application as part of your application logic in some document inside the same collection or a meta-collection yourself or you have to iterate over all documents to figure out the list of keys...there is nothing in MongoDB helping you here since MongoDB is schemaless.