<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="mysql-shell-tutorial-python-collections-operations">
      </a>
      22.4.3.1 Create, List, and Drop Collections
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045127245216">
  </a>
  <p>
   In MySQL Shell, you can create new collections, get a list of
        the existing collections in a schema, and remove an existing
        collection from a schema. Collection names are case-sensitive
        and each collection name must be unique.
  </p>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="idm46045127243040">
       </a>
       Confirm the Schema
      </h5>
     </div>
    </div>
   </div>
   <a class="indexterm" name="idm46045127242368">
   </a>
   <p>
    To show the value that is assigned to the schema variable,
          issue:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-mysqlsh"><div class="docs-select-all right" id="sa51964250"><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-mysqlsh"><span class="token prompt">mysql-py&gt;</span> db</code></pre>
   </div>
   <p>
    If the schema value is not
    <code class="literal">
     Schema:world_x
    </code>
    ,
          then set the
    <code class="literal">
     db
    </code>
    variable by issuing:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-mysqlsh"><div class="docs-select-all right" id="sa32049510"><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-mysqlsh"><span class="token prompt">mysql-py&gt;</span> \use world_x</code></pre>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="mysql-shell-tutorial-python-collections-create">
       </a>
       Create a Collection
      </h5>
     </div>
    </div>
   </div>
   <a class="indexterm" name="idm46045127233952">
   </a>
   <p>
    To create a new collection in an existing schema, use the
    <code class="literal">
     db
    </code>
    object's
    <code class="literal">
     createCollection()
    </code>
    method. The following
          example creates a collection called
    <code class="literal">
     flags
    </code>
    in the
    <code class="literal">
     world_x
    </code>
    schema.
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-mysqlsh"><div class="docs-select-all right" id="sa82186867"><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-mysqlsh"><span class="token prompt">mysql-py&gt;</span> db<span class="token punctuation">.</span><span class="token function">create_collection</span><span class="token punctuation">(</span><span class="token string">"flags"</span><span class="token punctuation">)</span></code></pre>
   </div>
   <p>
    The method returns a collection object.
   </p>
   <pre class="screen">&lt;Collection:flags&gt;</pre>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="mysql-shell-tutorial-python-collections-get">
       </a>
       List Collections
      </h5>
     </div>
    </div>
   </div>
   <a class="indexterm" name="idm46045127224944">
   </a>
   <p>
    To display all collections in the
    <code class="literal">
     world_x
    </code>
    schema, use the
    <code class="literal">
     db
    </code>
    object's
    <code class="literal">
     get_collections()
    </code>
    method. Collections
          returned by the server you are currently connected to appear
          between brackets.
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa13836416"><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-mysqlsh"><span class="token prompt">mysql-py&gt;</span> db<span class="token punctuation">.</span><span class="token function">get_collections</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">[</span>
    <span class="token operator">&lt;</span>Collection<span class="token punctuation">:</span>countryinfo<span class="token operator">&gt;</span><span class="token punctuation">,</span>
    <span class="token operator">&lt;</span>Collection<span class="token punctuation">:</span>flags<span class="token operator">&gt;</span>
<span class="token punctuation">]</span></code></pre>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="mysql-shell-tutorial-python-collections-drop">
       </a>
       Drop a Collection
      </h5>
     </div>
    </div>
   </div>
   <a class="indexterm" name="idm46045127217648">
   </a>
   <p>
    To drop an existing collection from a schema, use the
    <code class="literal">
     db
    </code>
    object's
    <code class="literal">
     drop_collection()
    </code>
    method. For example, to
          drop the
    <code class="literal">
     flags
    </code>
    collection from the current
          schema, issue:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-mysqlsh"><div class="docs-select-all right" id="sa38089652"><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-mysqlsh"><span class="token prompt">mysql-py&gt;</span> db<span class="token punctuation">.</span><span class="token function">drop_collection</span><span class="token punctuation">(</span><span class="token string">"flags"</span><span class="token punctuation">)</span></code></pre>
   </div>
   <p>
    The
    <code class="literal">
     drop_collection()
    </code>
    method is also used
          in MySQL Shell to drop a relational table from a schema.
   </p>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="idm46045127210512">
       </a>
       Related Information
      </h5>
     </div>
    </div>
   </div>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       See
       <a class="ulink" href="/doc/x-devapi-userguide/en/collection-objects.html" target="_top">
        Collection Objects
       </a>
       for more
              examples.
      </p>
     </li>
    </ul>
   </div>
  </div>
 </div>
 <br/>
</div>
