search

Home  >  Q&A  >  body text

nosql - mongodb如何设计schema

我们都知道mongodb是一种面向文档的数据库,但是它的灵活性并不意味着你不需要对其进行结构设计,在代码实施之前进行结构设计是十分必要的。

但是这样问题就来了,目前我们用的几乎所有的数据库设计工具都无法表现出mongodb这种面向文档的数据结构,那么我们在做设计的时候怎么样把我们的结构清晰的展现给别人呢,我可不想用ps一个一个去画框图。

PHP中文网PHP中文网2801 days ago971

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-04-21 10:59:19

    In fact, the design philosophy on the official website is quite good (http://www.mongodb.org/display/DOCS/S...)
    The biggest difference between MongoDB and traditional SQL schema design is which method is better to express the model relationship (in MongoDB, you can use either Link or Embedded)

    A brief summary:

    1. FirstClass (such as "User") should use an independent Collection
    2. "entry type" should be embedded
    3. If there is an inclusion relationship between two models, use embedded
    4. Many-to-many relationship, use link (similar to foreign key in SQL)
    5. If a model may store very few objects, then use an independent collection, which will help the mongodb server do caching
    6. The embedded method is not conducive to complex associations and complex queries
    7. The embedded method has great performance advantages. If you have "performance" requirements, you can consider using embed

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-21 10:59:19

    I am still used to treating mongodb as an ordinary DB, treating collections as tables, and the data structure in each collection remains consistent.
    I don’t know if this is reasonable, but at least it makes my thinking clearer.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-21 10:59:19

    NoSQL has a unique design philosophy, and it is recommended not to be influenced by RDB thinking.
    Also recommend an article to read:
    MongoDB record mapping schema extremely free Java Entity

    reply
    0
  • Cancelreply