现在需求是每个用户有一些项目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 ,不吝赐教。
PHP中文网2017-05-02 09:22:19
I think one table is enough in your case. mongodb
After all, it is a document database, and the data stored is highly scalable. Of course you can separate if you want. For reference only
仅有的幸福2017-05-02 09:22:19
It can be a table, but it is more embarrassing when updating the value specified by "p_id"
为情所困2017-05-02 09:22:19
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.