I'm new to Mongo and have been trying to suss out the best way to structure part of my database. Imagine a document building program in which a user composes a text document by select 'paragraphs' from a pre-defined template. My question is just about how to store the template structure; when a user saves their text document it's completely separate and uncomplex.
A full 'template' could look as follows (simplified). :
{
description: 'Template 1',
someOtherField: '',
. . .
sections: [
{
description: 'Section 1',
paragraphs: [
{
description: 'Paragraph A',
subparagraphs : [
{
text: 'This is some text',
optionalTexts: [
{
text: 'This is optional'
},
. . more . .
]
}
. . more . .
]
}
. . more . .
]
}
}
As you can see they are fairly nested and can potentially encompass a lot of data.
I'd be running queries to achieve things like "List the sections belonging to template 56", "Give me the paragraph objects for section 1234"; as well as administrative tasks on individual items, "Update the text of subparagraph 5678 to ..", "Create a new paragraph for section 7568..".
I currently have two collections:
- templates - template documents containing basic details and an array of sections.
- paragraphs - full paragraph documents (including nested subpagraphs, etc.). Each paragraph document has a field referencing the _id of a section in a template document.
Is this a more sensible approach than having one collection with even deeper nested document?
If there isn't an "answer" to my question, some good resources would be greatly appreciated.
Thanks