Hi there,
I’m fairly new to the MERN stack and have been learning on-the-go by working on small projects.
I have been working on simple TODO app. The idea is to allow the user to login/signup and start creating tasks or TODOs for the day.
I already have a “Users” Collection on MongoDB Atlas M0 Cluster, that is meant to store user information such as username, email and password.
I’m trying to figure out how I could store the tasks for a specific user. Initially, I was planning to have a separate Collection, Tasks, that would store the tasks from all users using the app.
Alternatively, I thought it would be a better idea to store the tasks as an Object, as an additional item in the Users document. For example, a document from the “Users” Collection would look like this:
{
_id: ObjectID(user1),
username: "user1",
email: "user1@mail.com",
password: "...",
tasks: {
ObjectId(task1): {
task: "task 1",
description: "description 1",
isComplete: true
},
ObjectId(task2): {
task: "task 2",
description: "description 2",
isComplete: false
},
...
}
}
I am inclining towards the latter approach as it would keep things segregated as all tasks would be stored inside their respective user’s document. However, I am aware that this may lead to a performance overhead in the longer run, and I would also have to be mindful of the memory limit.
Given that this is a small-scale, side project, I would appreciate any advice on which approach I could go with and any good practices I could keep in mind while implementing the same.
Thanks in advance!
Neilansh