mongodb 需不需要建多个表?
漂亮男人
漂亮男人 2017-05-02 09:20:19
0
3
706

现在需求是每个用户有一些项目projects,项目有分类tags

按照 mysql 的方法应该是建3张表,一张用户表,一张项目表,一张分类表,然后外键什么的。

如果是 mongo ,是不是一张表就够了?

{
    username: '',
    u_id: '132342131',
    projects: [
        {
            tags: 'editor',
            p_id: ['12312334','123345213','2352321313']
        },
        {
            tags: 'blogs',
            p_id: ['12312334','123345213','2352321313']
        }
    ]
}

初学 mongo ,不吝赐教。

漂亮男人
漂亮男人

reply all(3)
Ty80

I think one table is enough in your case. mongodbAfter all, it is a document database, and the data stored is highly scalable. Of course you can separate if you want. For reference only

仅有的幸福

It can be a table, but it is more embarrassing when updating the value specified by "p_id"

为情所困

I wish there were simple answers too. The question is, "should the data be put into a table?" is the most difficult part of MongoDB's data model design. The database design of MongoDB is not like SQL. The standard is whether it meets the third normal form. Things are much easier when there are standards. For MongoDB, it is a series of "if... then should... but if... then should..."
This is a big topic, and it is also the most important thing to learn when using MongoDB. Provide some information to study:
http://blog.mongodb.org/post/...
http://blog.mongodb.org/post/...
http://blog.mongodb.org/ post/…
https://docs.mongodb.com/manu…

The most basic question to consider is how you plan to use this data model. If your model performs well in most usage scenarios, it's a good design.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template