Big collection or small collections


I want to dev an app with users, teachers, students, calendar, scheduler, etc… One user only can access to his own data, never can see other students or calendar of another user (except admin who can access to every data).

I dont know the best model for tthis app with mongodb. What is better:

  1. Do every table as a little collection and put a userid key on every table

  2. Do one big collection for every user and nested documents or collections for.every table.

What is the best options for a good scalable and performance?

Thanks, i hope u can help me

Do it step by step

First you have user. So you need a user table off course.
Then you have teachers. Teachers are user.
The question is: Do you need more information on teachers or do you only need the information if a user is a teacher or a student? Depending on that you can create own table for teachers and students containing the user id or you can just add a “type” column to the users table.

The rest is not clear to me. What is the calendar and what the scheduler? What data do you want to save?

Uff, I’m so sorry for my english. It’s so hard for me explain my problem in not native language.

I have users, users can access to his data, and his data are students, teachers, shceduler, calendar, …

This means, every user have his own data, and this data it’s for app tables.

I have a mongodb, no sql.

Thanks, I hope I explained better now.

well we can understand your english. its ok. first of all you should make a structure for what you need, what you want to do an the goals and target

I prefer to have small collections. I’ve seen the alternative where a digit is used to represent the type of person in a large table and it gets ugly fast.

Tables are cheap, and on the odd-occasion that it’s needed it’s easy to join tables.
Use a separate small collection of tables.

I would prefer smaller collections in this case. One collection for people, another for appointments. You can easily fetch all appointments from a user by selecting on the user id in each document.

The main reason is that big documents get slower over time. When you want to get just one appointment, you still need to get all appointments from the user at once, and when you want to add a new appointment you first need to get all appointments from the user, add the appointment and then save all the appointments again.

When appointments are saved individually you don’t have that problem.

Ok, thanks for all. I’ll continue with small collections separated, and make connect them with UserId. Thanks!

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.