We all know mongodb is a document-oriented database, but its flexibility doesn’t mean that you don’t need to carry out structural design. It is very necessary to carry out structural design before code implementation.
However, the problem arises. Almost all the database design tools we use at present cannot show mongodb as a document-oriented data structure. So how can we clearly show our structure to others when we do design? I don’t want to use ps to remove picture frames one by one.
In fact, this design philosophy of the official website is very good (http://www.mongodb.org/display/DOCS/S …)
The biggest difference between MongoDB and traditional SQL schema design is about which method is better to express the model relationship (Link and Embedded can be used in MongoDB)
To summarize briefly:
- FirstClass (such as “User”) should use a separate Collection
- “Item type”, should be embedded
- If the two models are inclusive, embedded is used
- Many-to-many relation, using link (similar to the foregin key in sql)
- If a model may have few objects, then use a separate collection, which helps mongodb server to do caching.
- Embedded mode is not conducive to making complex association and complex query.
- Embedded mode has great performance advantages. if you have “performance” requirements, you can consider using embedded mode.