Ok so I am coming from a mySQL background and am now trying to rebuild a 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 the best way to restructure this old mySQL schema to work with Mongoose?
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 comment size (currently mongodb max document size is 16 mb), you can move it to other doc
In this way you can find the users of the group by
db.users.find({Groups:'groupid1'})
also the groups the user belongs to
db.users.find({id:userid},{Groups:1})
if you wanted to retrieve the group relevent info with the above query, i suggest you to store most frequently access group fields also with users.groups, like this
users
user_ID
user_name
user_email
user_password
Groups
- { grupid 1,name}
- {grupid 2,name}
- {grupid 3,name}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With