查询 MongoDB 集合中所有不同字段的列表

编程入门 行业动态 更新时间:2024-10-27 10:18:56
本文介绍了查询 MongoDB 集合中所有不同字段的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个集合,其中存储了所有表单数据,每个表单具有不同的结构,但有些表单具有重叠的字段名称.我喜欢 mongo,因为它在这里证明了它的易用性,它允许我根据一些小的共同因素对完全不同的数据进行排序和聚合.

I have a collection where all form data is stored, each form with a different structure, but some forms with overlapping field names. I love mongo for the ease it proves here, allowing me to sort and aggregate totally different data based upon a few small common factors.

现在,对于 UI,我需要数据库中所有可能字段的列表,以便用户可以选择要查看的字段.除了索引,我似乎找不到任何 mongo 任何东西来返回字段列表.

Now, for the UI, I need a list of all possible fields in the database so a user can choose which fields to view. I can't seem to find any mongo anything to return a list of fields, except for indexes.

我该怎么做?

推荐答案

没有提供此信息的本机 MongoDB 功能.MongoDB 是完全无模式的,因此您必须执行完整的数据库遍历才能编译所有唯一字段名称的列表.

There is no native MongoDB functionality that provides this information. MongoDB is completely schemaless and as such you will have to do a full database walk to compile a list of all unique field names.

唯一可能的解决方法是使用 {field: <field name>, value: <field value>} 对存储所有字段并对字段"运行不同的操作或维护数据库中单独的唯一字段名称列表.两者都有明显的缺点.

The only possible workarounds are to store all fields using {field: <field name>, value: <field value>} pairs and run a distinct operation on "field" or to maintain a list of unique field names seperately in the database. Both have significant downsides.

更多推荐

查询 MongoDB 集合中所有不同字段的列表

本文发布于:2023-11-22 20:19:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1618871.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   列表   MongoDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!