Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the most efficient JSON / mongodb document structure for search and CMS use?
    primarykey
    data
    text
    <p>I am working on a document structure that can be searched easily while maintaining a rebuildable structure. By that I mean the document itself holds the information required for a CMS to build the needed forms for updating the document.</p> <p>The key point being that the final structure of the document will never be known, as it will built / modified via the CMS.</p> <p>The goal is to ensure the front end content methods can search quickly, while making the CMS able to rebuild the content so it can be managed. I have no qualms with making the admin area of the CMS work harder, speed is not as crucial there.</p> <p><strong>Here is a basic example</strong></p> <p>This is a highly abbreviated document, but it may illustrate my points. This document is relatively easy to query, but it has no structural information about how a CMS would display it.</p> <pre><code>{ "name" : "Page Name", "title" : "Page Title", "description" : "Page Description", "page_heading" : "New Heading", "content_body" : "&lt;p&gt;New Content&lt;/p&gt;", "slideshow" : [ { "image_title" : "Vacation Hawaii", "image_file" : "hawaii100.jpg" }, { "image_title" : "Vacation Spain", "image_file" : "Spain200.jpg" }, ] } </code></pre> <p><strong>Here is an example with abbreviated structural data</strong></p> <p>The problem with this approach is that queries become more difficult. </p> <pre><code>&gt; db.posts.find( { page_heading.value : "example" } ) </code></pre> <p>--</p> <pre><code> { "name" : "Page Name", "title" : "Page Title", "description" : "Page Description", "page_heading" : { "value" : "This is the page heading", "type" : "string", }, "content_body" : { "value" : "&lt;p&gt;HTML Content&lt;/p&gt;", "type" : "html_textarea", }, "slideshow" : { "type" : { "image_title" : "string", "image_file" : "file" }, "value" : [ { "image_title" : "Vacation Hawaii", "image_file" : "hawaii100.jpg" }, { "image_title" : "Vacation Spain", "image_file" : "Spain200.jpg" }, ] } } </code></pre> <p><strong>Alternative Approach</strong></p> <p>Having separate documents, one for the data and one for the template, seems like a possible solution, but increases the logistical complexity a bit.</p> <p><strong>Content Document linking to template</strong></p> <pre><code> { "name" : "Page Name", "title" : "Page Title", "description" : "Page Description", "template" : "document_id", "page_heading" : "New Heading", "content_body" : "&lt;p&gt;New Content&lt;/p&gt;", "slideshow" : [ { "image_title" : "Vacation Hawaii", "image_file" : "hawaii100.jpg" }, { "image_title" : "Vacation Spain", "image_file" : "Spain200.jpg" }, ] } </code></pre> <p><strong>Template Document</strong></p> <pre><code>{ "parent" : "document_id", "page_heading" : { "type" : "string", "required" : true }, "content_body" : { "type" : "html_textarea", "required" : true }, "slideshow" : { "type" : { "image_title" : "string", "image_file" : "file" } } } </code></pre> <p>What is the best approach?</p> <p>It is highly possible that I am over complicating the whole thing and that there is a simple solution right in front of me.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload