<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="document-store-concepts">
      </a>
      22.2 Document Store Concepts
     </h2>
    </div>
   </div>
  </div>
  <p>
   This section explains the concepts introduced as part of using
      MySQL as a document store.
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="xref" href="document-store-concepts.html#document-store-concepts-json-document" title="JSON Document">
       JSON Document
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="document-store-concepts.html#document-store-concepts-collection" title="Collection">
       Collection
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="document-store-concepts.html#document-store-concepts-crud-operation" title="CRUD Operations">
       CRUD Operations
      </a>
     </p>
    </li>
   </ul>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="document-store-concepts-json-document">
       </a>
       JSON Document
      </h3>
     </div>
    </div>
   </div>
   <p>
    A JSON document is a data structure composed of key-value pairs
        and is the fundamental structure for using MySQL as document
        store. For example, the world_x schema (installed later in this
        chapter) contains this document:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-json"><div class="docs-select-all right" id="sa41173062"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-json"><span class="token punctuation">{</span>
    <span class="token property">"GNP"</span><span class="token operator">:</span> <span class="token number">4834</span><span class="token punctuation">,</span>
    <span class="token property">"_id"</span><span class="token operator">:</span> <span class="token string">"00005de917d80000000000000023"</span><span class="token punctuation">,</span>
    <span class="token property">"Code"</span><span class="token operator">:</span> <span class="token string">"BWA"</span><span class="token punctuation">,</span>
    <span class="token property">"Name"</span><span class="token operator">:</span> <span class="token string">"Botswana"</span><span class="token punctuation">,</span>
    <span class="token property">"IndepYear"</span><span class="token operator">:</span> <span class="token number">1966</span><span class="token punctuation">,</span>
    <span class="token property">"geography"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">"Region"</span><span class="token operator">:</span> <span class="token string">"Southern Africa"</span><span class="token punctuation">,</span>
        <span class="token property">"Continent"</span><span class="token operator">:</span> <span class="token string">"Africa"</span><span class="token punctuation">,</span>
        <span class="token property">"SurfaceArea"</span><span class="token operator">:</span> <span class="token number">581730</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token property">"government"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">"HeadOfState"</span><span class="token operator">:</span> <span class="token string">"Festus G. Mogae"</span><span class="token punctuation">,</span>
        <span class="token property">"GovernmentForm"</span><span class="token operator">:</span> <span class="token string">"Republic"</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token property">"demographics"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">"Population"</span><span class="token operator">:</span> <span class="token number">1622000</span><span class="token punctuation">,</span>
        <span class="token property">"LifeExpectancy"</span><span class="token operator">:</span> <span class="token number">39.29999923706055</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre>
   </div>
   <p>
    This document shows that the values of keys can be simple data
        types, such as integers or strings, but can also contain other
        documents, arrays, and lists of documents. For example, the
    <code class="literal">
     geography
    </code>
    key's value consists of multiple
        key-value pairs. A JSON document is represented internally using
        the MySQL binary JSON object, through the
    <a class="link" href="json.html" title="13.5 The JSON Data Type">
     <code class="literal">
      JSON
     </code>
    </a>
    MySQL datatype.
   </p>
   <p>
    The most important differences between a document and the tables
        known from traditional relational databases are that the
        structure of a document does not have to be defined in advance,
        and a collection can contain multiple documents with different
        structures. Relational tables on the other hand require that
        their structure be defined, and all rows in the table must
        contain the same columns.
   </p>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="document-store-concepts-collection">
       </a>
       Collection
      </h3>
     </div>
    </div>
   </div>
   <p>
    A collection is a container that is used to store JSON documents
        in a MySQL database. Applications usually run operations against
        a collection of documents, for example to find a specific
        document.
   </p>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="document-store-concepts-crud-operation">
       </a>
       CRUD Operations
      </h3>
     </div>
    </div>
   </div>
   <p>
    The four basic operations that can be issued against a
        collection are Create, Read, Update and Delete (CRUD). In terms
        of MySQL this means:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       Create a new document (insertion or addition)
      </p>
     </li>
     <li class="listitem">
      <p>
       Read one or more documents (queries)
      </p>
     </li>
     <li class="listitem">
      <p>
       Update one or more documents
      </p>
     </li>
     <li class="listitem">
      <p>
       Delete one or more documents
      </p>
     </li>
    </ul>
   </div>
  </div>
 </div>
 <br/>
</div>
