Answer the question
In order to leave comments, you need to log in
How to organize MongoDB database structure?
I'm creating a simple note-taking app like google keep.
Each user has notes and a list of labels, each note can have multiple labels.
Actually the question is: should I create separate models for labels and notes, or store them in the user's document? If separately, how best to group them for each user?
Answer the question
In order to leave comments, you need to log in
It really all depends on the functionality that you want to implement.
I would do it all as separate models, so it will be possible to implement their normal editing and modification, with a pull-up to all created entities.
That is, the structure would look something like this:
User {
_id: ObjectId('...'),
notes: [
ObjectId('Note1...'),
ObjectId('Note2...'),
ObjectId('Note3...')
]
}
Note {
_id: ObjectId('Note1...'),
...,
labels: [
ObjectId('Label 1'),
ObjectId('Label 2'),
]
}
Label {
_id: ObjectId('Label 1'),
name: "Label 1"
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question