在 mongodb 中访问字段名作为元数据

发布于 2024-11-25 12:43:01 字数 276 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满栀 2024-12-02 12:43:01

要么您将应用程序中使用过的密钥列表作为应用程序逻辑的一部分,保存在同一集合或元集合中的​​某个文档中,要么您必须迭代所有文档以找出密钥列表...有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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文