Many-to-many relationships in CouchDB or MongoDB

点点圈 提交于 2019-11-30 12:26:10

For CouchDB, I would highly recommend reading this article about Entity Relationships.

One thing I would note in CouchDB is to be careful of attempting to "normalize" a non-relational data model. 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. 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).

If you can: consider redesign your application using embedded documents.

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

In general: try to turn off your memories to a RDBMS when working with MongoDB. Blindly copying the database design from RDBMS to MongoDB is neither helpful nor adviceable nor will it work in general.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!