【发布时间】:2019-05-01 15:00:45
【问题描述】:
我一直在努力构建我的 mongodb,但我刚刚意识到我实际上并没有花时间思考最佳策略,我可能会滥用 nosql 结构并构建更传统的关系结构。我正在建立一个社区论坛,目前我拥有的收藏如下:
User - stores all user settings/data such as email, name, password, date joined, email/notification preferences, etc..
Profile - stores handle, gender, user location, forum rank, interests and then several arrays containing id's of things like an array of follower id's, array of post ids, array of upload id's, array of club id's, array of posts the user has liked, etc.
Posts - stores comment data, creator user id, category and then has an array of id's to uploaded files and an array of user id's for likes.
Uploads - GridFS schema to use when uploading files
我现在意识到,其他集合中的所有这些 id 数组的行为更像是关系数据库,尤其是 Profile 模式,它基本上只是其他集合的 id 集合。您能否就我正在创建的数据库类型以及如何改进它提供任何建议?例如,我是否应该有一个单一的用户模式,它直接在其中包含所有帖子和个人资料数据,而不是将 id 存储到不同集合中的单独模式?由于我正在使用这个项目来学习,我真的很想继续使用 mongodb,而不是迁移到 MySQL 之类的东西。
【问题讨论】:
-
我认为除了
UserProfile和Posts集合之外,您不需要任何其他东西。我没有遵循Uploads架构的想法,但如果这些是上传到帖子的文件,那么它们应该是Posts中的一个数组。User&Profile应该是一个模型,因为我认为没有理由将它们分开。
标签: mongodb mongoose nosql schema