Mongoose: proposed database schema

Okay, that's why I'm starting from mySQL background, and now I'm trying to rebuild the site using nodeJS and Mongoose. My old mySQL schema looked something like this (simplified):

users user_ID user_name user_email user_password groups group_ID group_name group_description groupusers groupuser_ID group_ID user_ID comments comment_ID group_ID user_ID comment_txt 

Can anyone suggest a better way to rebuild this old mySQL schema to work with Mongoose?

+7
source share
1 answer
 users user_ID user_name user_email user_password Groups - grupid 1 - grupid 2 - grupid 3 groups group_ID group_name group_description comments 1 - user_ID comment_txt 2 - user_ID comment_txt 

If you are worried about the size of the comment (currently the maximum mongodb file size is 16 mb), you can move it to another document

This way you can find group users

  db.users.find({Groups:'groupid1'}) 

also groups to which the user belongs

  db.users.find({id:userid},{Groups:1}) 

if you want to get information related to a group with the above request, I suggest that you store the most frequently used group fields also with user groups, for example

 users user_ID user_name user_email user_password Groups - { grupid 1,name} - {grupid 2,name} - {grupid 3,name} 
+5
source

All Articles