Reputation: 95
I'm in the process of migrating my application's database from MySQL to NoSQL(MongoDB). However, I'm a bit confused as to how I should structure my MongoDB.
In my current MySQL setup, I have two tables, one for users and one for calendars. Each user and calendar have a unique ID. Each user entry contains a list of the calendar IDs associated with that user. Each calendar entry also contains the ID of the user who made it.
The problem I am facing is that I have two situations: For the login console, I must quickly show the user all the calendar he/she has created; for the frontend website, I need to display all available calendars with their author.
In MySQL I would use JOINs to query this data really quickly. How do I achieve this same functionality in MongoDB (or any NoSQL database)?
Upvotes: 1
Views: 452
Reputation: 230306
You almost came to the conclusion. There are only two options without joins.
Both approaches have their pros and cons, which were discussed many times (try googling for " mongodb embed or reference")
In short: embedding gives you quicker reads, referencing gives you richer queries and easier/faster writes.
Upvotes: 2