<section>
 <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
  db.collection.storageSize()
  <a class="headerlink leafygreen-ui-1kepx47" href="#db.collection.storagesize--" title="Permalink to this heading">
   <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
    <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
    </path>
    <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
    </path>
   </svg>
   <div class="css-1btu0w3 evvkmar0" id="db.collection.storagesize--">
   </div>
  </a>
 </h1>
 <dl class="method">
  <dt>
   <code class="leafygreen-ui-1l06pbn">
    db.collection.storageSize()
   </code>
   <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-db.collection.storageSize" title="Permalink to this definition">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="mongodb-method-db.collection.storageSize">
    </div>
   </a>
  </dt>
  <dd>
   <div class="leafygreen-ui-85da11" role="note">
    <h2 class="leafygreen-ui-1ac4g5h">
     Important
    </h2>
    <h3 class="leafygreen-ui-144d5kf">
     <strong>
      mongosh Method
     </strong>
    </h3>
    <div class="leafygreen-ui-9mycqc">
     <p class="leafygreen-ui-1kp3ins">
      This page documents a
      <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
       <span>
        <code class="leafygreen-ui-1l06pbn">
         mongosh
        </code>
       </span>
      </a>
      method. This is
      <em>
       not
      </em>
      the documentation for database commands or language-specific drivers,
such as Node.js.
     </p>
     <p class="leafygreen-ui-1kp3ins">
      For the database command, see the
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collStats/#mongodb-data-collStats.storageSize">
       <code class="leafygreen-ui-1l06pbn">
        storageSize
       </code>
      </a>
      field returned
by the
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collStats/#mongodb-dbcommand-dbcmd.collStats">
       <code class="leafygreen-ui-1l06pbn">
        collStats
       </code>
      </a>
      command
      <!-- -->
      .
     </p>
     <p class="leafygreen-ui-1kp3ins">
      For MongoDB API drivers, refer to the language-specific
      <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
       <span>
        MongoDB driver documentation
        <!-- -->
        .
       </span>
      </a>
     </p>
    </div>
   </div>
   <table class="css-11h39yh e1nex8bq0">
    <colgroup>
     <col class="field-name"/>
     <col class="field-body"/>
    </colgroup>
    <tbody>
     <tr class="css-x8snli">
      <th>
       Returns
       <!-- -->
       :
      </th>
      <td>
       The total amount of storage in bytes allocated to this
collection for document storage.
       <p class="leafygreen-ui-1kp3ins">
        If collection data is compressed (which is the
        <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--wiredTigerCollectionBlockCompressor">
         <code class="leafygreen-ui-1l06pbn">
          default for WiredTiger
         </code>
        </a>
        ), the storage size
reflects the compressed size and may be smaller than the
value returned by
        <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.dataSize/#mongodb-method-db.collection.dataSize">
         <code class="leafygreen-ui-1l06pbn">
          db.collection.dataSize()
         </code>
         .
        </a>
       </p>
      </td>
     </tr>
    </tbody>
   </table>
   <p class="leafygreen-ui-1kp3ins">
    To run on a replica set member,
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collStats/#mongodb-dbcommand-dbcmd.collStats">
     <code class="leafygreen-ui-1l06pbn">
      collStats
     </code>
    </a>
    operations require the member
to be in
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.PRIMARY">
     <code class="leafygreen-ui-1l06pbn">
      PRIMARY
     </code>
    </a>
    or
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.SECONDARY">
     <code class="leafygreen-ui-1l06pbn">
      SECONDARY
     </code>
    </a>
    state. If the member
is in another state, such as
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.STARTUP2">
     <code class="leafygreen-ui-1l06pbn">
      STARTUP2
     </code>
    </a>
    , the
operation errors.
   </p>
  </dd>
 </dl>
</section>
