简体   繁体   English

CouchDB或MongoDB中的多对多关系

[英]Many-to-many relationships in CouchDB or MongoDB

I have an MSSQL database which I am considering porting to CouchDB or MongoDB. 我有一个MSSQL数据库,我正在考虑移植到CouchDB或MongoDB。 I have a many-to-many relationship within the SQL db which has hundreds of thousands rows in the xref table, corresponding to tens of thousands of rows in the tables on each side of the relationship. 我在SQL数据库中有多对多的关系,它在外部参照表中有数十万行,对应于关系两侧表中的数万行。 Will CouchDB and/or MongoDB be able to handle this data, and what would be the best way of formatting the relevant documents for performant querying? CouchDB和/或MongoDB是否能够处理这些数据,以及为性能查询格式化相关文档的最佳方法是什么? Thanks very much. 非常感谢。

For CouchDB, I would highly recommend reading this article about Entity Relationships. 对于CouchDB,我强烈建议您阅读有关实体关系的文章

One thing I would note in CouchDB is to be careful of attempting to "normalize" a non-relational data model. 我在CouchDB中要注意的一件事是要小心尝试“规范化”非关系数据模型。 The document-based storage offers you a great deal of flexibility, and it's seldom the best idea to abstract everything into as many "document types" as you can think of. 基于文档的存储为您提供了极大的灵活性,而且很难将所有内容抽象为您能想到的尽可能多的“文档类型”。 Many times, it's best to leave much of your data within the same document unless you have clear cases where separate entities exist. 很多时候,除非您有明确存在单独实体的情况,否则最好将大部分数据保留在同一文档中。

One common use-case of many-to-many relationships is implementing tagging. 多对多关系的一个常见用例是实现标记。 There are articles about different methods you can use to accomplish this in CouchDB. 有些文章介绍了在CouchDB中可以使用的不同方法。 It may apply to your requirements, it may not, but it's probably worth a read. 它可能适用于您的要求,也可能不适用,但它可能值得一读。

Since the 'collection' model of MongoDB is similar to tables you can of course maintain the m:n relationship inside a dedicated mapping collection (using the _id of the related documents of the referenced documents from other collections). 由于MongoDB的“集合”模型类似于表,您当然可以在专用映射集合中维护m:n关系(使用其他集合中引用文档的相关文档的_id)。

If you can: consider redesign your application using embedded documents. 如果可以:考虑使用嵌入式文档重新设计应用程序。

http://www.mongodb.org/display/DOCS/Schema+Design http://www.mongodb.org/display/DOCS/Schema+Design

In general: try to turn off your memories to a RDBMS when working with MongoDB. 一般来说:在使用MongoDB时,尝试关闭RDBMS的记忆。 Blindly copying the database design from RDBMS to MongoDB is neither helpful nor adviceable nor will it work in general. 盲目地将数据库设计从RDBMS复制到MongoDB既没有帮助也没有建议也没有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM