相当于 MongoDB 的 ERD?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6010408/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Equivalent of ERD for MongoDB?
提问by Catalin Braescu
What would be the equivalent of ERD for a NoSQL database such as MongoDB?
对于 NoSQL 数据库(例如 MongoDB)来说,ERD 的等价物是什么?
回答by Gates VP
It looks like you asked a similar question on Quora.
As mentioned there, the ERD is simply a mapping of the data you intend to store and the relations amongst that data.
正如那里提到的,ERD 只是您打算存储的数据的映射以及该数据之间的关系。
You can still make an ERD with MongoDB as you still want to track the data and the relations. The big difference is that MongoDB has no joins, so when you translate the ERD into an actual schema you'll have to make some specific decisions about implement the relationships.
您仍然可以使用 MongoDB 创建 ERD,因为您仍然希望跟踪数据和关系。最大的不同在于 MongoDB 没有连接,因此当您将 ERD 转换为实际模式时,您必须做出一些关于实现关系的具体决定。
In particular, you'll need to make the "embed vs. reference"decision when deciding how this data will actually be stored. Relations are still allowed, just not enforced. Many of the wrappers for MongoDB actually provide lookups across collections to abstract some of this complexity.
特别是,在决定如何实际存储这些数据时,您需要做出“嵌入与引用”的决定。关系仍然是允许的,只是没有强制执行。MongoDB 的许多包装器实际上提供跨集合的查找来抽象一些这种复杂性。
Even though MongoDB does not enforce a schema, it's not recommended to proceed completely at random. Modeling the data you expect to have in the system is still a really good idea and that's what the ERD provides you.
即使 MongoDB 不强制执行模式,也不建议完全随机进行。对您希望在系统中拥有的数据进行建模仍然是一个非常好的主意,而这正是 ERD 为您提供的。
So I guess the equivalent to the ERD is the ERD?
所以我猜 ERD 的等价物是ERD?
回答by sinha
You could just use a UML class diagram instead too.
您也可以只使用 UML 类图。
回答by Rob Raisch
I know of no standard means of diagramming document-oriented "schema".
我不知道绘制面向文档的“模式”的标准方法。
I'm sure you could use an ERD to map out your schemata but since document databases do not truly support--or more importantly enforce--relationships between data, it would only be as useful as your code was disciplined to internally enforce such relationships.
我确信您可以使用 ERD 来绘制您的模式,但由于文档数据库并不真正支持——或者更重要的是强制——数据之间的关系,它只会和你的代码在内部强制执行这种关系一样有用.
回答by Gabriel C
I have been thinking about the same issue for quite some time. And I came to the following conclusion: If NoSQL databases are generally schemaless, you don't actually have a 'schema' to illustrate in a diagram.
很长一段时间以来,我一直在思考同样的问题。我得出以下结论:如果 NoSQL 数据库通常是无模式的,那么您实际上没有“模式”可以在图表中进行说明。
Thus, I think you should take a "by example" approach. You could draw some mindmaps exemplifying how your data would look like when stored in a NoSQL DB such as MongoDB.
因此,我认为您应该采取“通过示例”的方法。您可以绘制一些思维导图,举例说明您的数据存储在 NoSQL DB(如 MongoDB)中时的样子。
And since these databases are very dynamic you could also create some derived mindmaps to show how the data from today could evolve in time.
由于这些数据库非常动态,您还可以创建一些派生的思维导图来展示今天的数据如何及时演变。
Take a look at this topic too.
也看看这个话题。
回答by Vaclav
Moon Modelersupports schema design for MongoDB. It allows users to define diagrams with nested structures.
Moon Modeler支持 MongoDB 的模式设计。它允许用户定义具有嵌套结构的图表。
回答by Donato
MongoDB does support 'joins', just not in the SQL sense of INNER JOIN (the default SQL join). While the concept of 'join' is typically associated with SQL, MongoDB does have the aggregation framework with its data processing pipeline stages. The $lookup pipeline stage is used to create the equivalent of a LEFT JOIN in SQL. That is, all documents on the left of a relationship will be pass through the pipeline, as well as any relating documents on the right side of the relationship. The documents are modified to include the relationship as part of the new documents.
MongoDB 确实支持“连接”,只是不支持 INNER JOIN(默认 SQL 连接)的 SQL 意义。虽然“连接”的概念通常与 SQL 相关联,但 MongoDB 确实具有聚合框架及其数据处理管道阶段。$lookup 管道阶段用于在 SQL 中创建等效的 LEFT JOIN。也就是说,关系左侧的所有文档以及关系右侧的所有相关文档都将通过管道。修改文档以将关系包含在新文档中。
Consequently, I postulate that Entity Relationship Diagrams do have a role in MongoDB. Documents are certainly related to each other in the db, and we should have a visualization of these relationships, including the cardinality relationship, e.g. full participation, partial participation, weak/strong entities, etc.
因此,我假设实体关系图在 MongoDB 中确实有作用。文档在db中肯定是相互关联的,我们应该对这些关系进行可视化,包括基数关系,例如完全参与、部分参与、弱/强实体等。
Of course, MongoDB also introduces the concept of embedded documents and referenced documents, and so I argue it adds additional flavor to the model of the ERD. And I certainly would want to see embedded and referenced relationships mapped out in a visual diagram.
当然,MongoDB 还引入了嵌入文档和引用文档的概念,因此我认为它为 ERD 模型添加了额外的风味。而且我当然希望在可视化图表中看到嵌入和引用的关系。
The remaining question is so what is out there? What is out there for Mongoose for NodeJS? Mongoid for Ruby? etc. If you check the respective repositories for their corresponding ORMs (Object Relational Mappers), then you will see there are ERDs for them. But in terms of their completeness, perhaps there is a lot to be desired and the open source community is welcome to make contributions.
剩下的问题是那里有什么?Mongoose for NodeJS 有什么用?Ruby 的 Mongoid?等。如果您检查相应的存储库中的相应 ORM(对象关系映射器),那么您将看到它们有 ERD。但就其完整性而言,也许还有很多不足之处,欢迎开源社区做出贡献。