title: MongoDB design - large nested document, or split across multiple collections?
body: <p>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.</p>
  
  <p>A full 'template' could look as follows (simplified). :</p>
  
  <pre><code>{
      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 . .
              ]
          }
  }
  </code></pre>
  
  <p>As you can see they are fairly nested and can potentially encompass a lot of data. </p>
  
  <p>I'd be running queries to achieve things like <em>"List the sections belonging to template 56"</em>, <em>"Give me the paragraph objects for section 1234"</em>; as well as administrative tasks on individual items, <em>"Update the text of subparagraph 5678 to .."</em>, <em>"Create a new paragraph for section 7568.."</em>. </p>
  
  <p>I currently have two collections:</p>
  
  <ul>
  <li><strong>templates</strong> - template documents containing basic details and an array of sections.</li>
  <li><strong>paragraphs</strong> - full paragraph documents (including nested subpagraphs, etc.). Each paragraph document has a field referencing the _id of a section in a template document.</li>
  </ul>
  
  <p>Is this a more sensible approach than having one collection with even deeper nested document? </p>
  
  <p>If there isn't an "answer" to my question, some good resources would be greatly appreciated.</p>
  
  <p>Thanks</p>