<section>
 <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
  Change the Oplog Size of Self-Managed Replica Set Members
  <a class="headerlink leafygreen-ui-1kepx47" href="#change-the-oplog-size-of-self-managed-replica-set-members" 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="change-the-oplog-size-of-self-managed-replica-set-members">
   </div>
  </a>
 </h1>
 <div class="leafygreen-ui-a5yxub">
  <p class="css-1cmx2d4 ef7gu8j0">
   On this page
  </p>
  <ul class="css-1qb0mst ef7gu8j1">
   <li class="leafygreen-ui-1e7a0ei">
    <a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#a.-connect-to-the-replica-set-member" target="_self">
     <span>
      A. Connect to the replica set member
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#b.--optional--verify-the-current-size-of-the-oplog" target="_self">
     <span>
      B. (Optional) Verify the current size of the oplog
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#c.-change-the-oplog-size-of-the-replica-set-member" target="_self">
     <span>
      C. Change the oplog size of the replica set member
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#d.--optional--compact-oplog.rs-to-reclaim-disk-space" target="_self">
     <span>
      D. (Optional) Compact
      <code class="css-1kekw28 e1wawog0">
       oplog.rs
      </code>
      to reclaim disk space
     </span>
    </a>
   </li>
  </ul>
 </div>
 <div class="leafygreen-ui-1sjx7ru" role="note">
  <h2 class="leafygreen-ui-29m78u">
   Warning
  </h2>
  <div class="leafygreen-ui-9mycqc">
   <p class="leafygreen-ui-1kp3ins">
    You cannot drop the
    <code class="leafygreen-ui-1l06pbn">
     local.oplog.rs
    </code>
    collection. For more information on
this restriction, see
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-oplog/#std-label-oplog-coll-behavior">
     Oplog Collection Behavior
     <!-- -->
     .
    </a>
   </p>
  </div>
 </div>
 <p class="leafygreen-ui-1kp3ins">
  This procedure changes the size of the oplog
  <a class="footnote-reference header-buffer" href="#footnote-oplog" id="ref-oplog-id1">
   [
   <!-- -->
   1
   <!-- -->
   ]
  </a>
  on each member of a
replica set using the
  <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetResizeOplog/#mongodb-dbcommand-dbcmd.replSetResizeOplog">
   <code class="leafygreen-ui-1l06pbn">
    replSetResizeOplog
   </code>
  </a>
  command, starting
with the
  <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
   secondary
  </a>
  members before proceeding to the
  <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
   primary
   <!-- -->
   .
  </a>
 </p>
 <p class="leafygreen-ui-1kp3ins">
  Perform these steps on each
  <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
   secondary
  </a>
  replica set member
  <em>
   first
  </em>
  . Once you have changed the oplog size for all secondary
members, perform these steps on the
  <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
   primary
   <!-- -->
   .
  </a>
 </p>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   A. Connect to the replica set member
   <a class="headerlink leafygreen-ui-1kepx47" href="#a.-connect-to-the-replica-set-member" 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="a.-connect-to-the-replica-set-member">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   Connect to the replica set member using
   <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>
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongosh --host &lt;hostname&gt;:&lt;port&gt;","programmingLanguage":"Bash"}
  </script>
  <div class="css-16lmvu9">
   <div class="leafygreen-ui-196mwvg">
    <div class="leafygreen-ui-yzcs8i">
     <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongosh --host &lt;hostname&gt;:&lt;port&gt;</td></tr></tbody></table></code></pre>
     <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
      <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
       <div class="leafygreen-ui-xhlipt">
        <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
         <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
         </path>
        </svg>
       </div>
      </button>
     </div>
    </div>
   </div>
  </div>
  <div class="leafygreen-ui-15mdk4" role="note">
   <h2 class="leafygreen-ui-6n7b7d">
    Note
   </h2>
   <div class="leafygreen-ui-9mycqc">
    <p class="leafygreen-ui-1kp3ins">
     If the replica set enforces
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-authentication">
      authentication
     </a>
     ,
you must authenticate as a user with privileges to modify the
     <code class="leafygreen-ui-1l06pbn">
      local
     </code>
     database, such as the
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterManager">
      <code class="leafygreen-ui-1l06pbn">
       clusterManager
      </code>
     </a>
     or
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterAdmin">
      <code class="leafygreen-ui-1l06pbn">
       clusterAdmin
      </code>
     </a>
     role.
    </p>
   </div>
  </div>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   B. (Optional) Verify the current size of the oplog
   <a class="headerlink leafygreen-ui-1kepx47" href="#b.--optional--verify-the-current-size-of-the-oplog" 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="b.--optional--verify-the-current-size-of-the-oplog">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   To view the current size of the oplog, switch to the
   <code class="leafygreen-ui-1l06pbn">
    local
   </code>
   database and run
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.stats/#mongodb-method-db.collection.stats">
    <code class="leafygreen-ui-1l06pbn">
     db.collection.stats()
    </code>
   </a>
   against the
   <code class="leafygreen-ui-1l06pbn">
    oplog.rs
   </code>
   collection.
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.stats/#mongodb-method-db.collection.stats">
    <code class="leafygreen-ui-1l06pbn">
     stats()
    </code>
   </a>
   displays the
oplog size as
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collStats/#mongodb-data-collStats.maxSize">
    <code class="leafygreen-ui-1l06pbn">
     maxSize
    </code>
    .
   </a>
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"use local\ndb.oplog.rs.stats().maxSize","programmingLanguage":"JavaScript"}
  </script>
  <div class="css-16lmvu9">
   <div class="leafygreen-ui-196mwvg">
    <div class="leafygreen-ui-yzcs8i">
     <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">use local</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">oplog</span>.<span class="lg-highlight-property">rs</span>.<span class="lg-highlight-title lg-highlight-function">stats</span>(<!-- -->).<span class="lg-highlight-property">maxSize</span></td></tr></tbody></table></code></pre>
     <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
      <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
       <div class="leafygreen-ui-xhlipt">
        <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
         <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
         </path>
        </svg>
       </div>
      </button>
     </div>
    </div>
   </div>
  </div>
  <p class="leafygreen-ui-1kp3ins">
   The
   <code class="leafygreen-ui-1l06pbn">
    maxSize
   </code>
   field displays the collection size in bytes.
  </p>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   C. Change the oplog size of the replica set member
   <a class="headerlink leafygreen-ui-1kepx47" href="#c.-change-the-oplog-size-of-the-replica-set-member" 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="c.-change-the-oplog-size-of-the-replica-set-member">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   Resize the oplog with the
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetResizeOplog/#mongodb-dbcommand-dbcmd.replSetResizeOplog">
    <code class="leafygreen-ui-1l06pbn">
     replSetResizeOplog
    </code>
   </a>
   command. The
   <code class="leafygreen-ui-1l06pbn">
    size
   </code>
   is a double and must be greater than
   <code class="leafygreen-ui-1l06pbn">
    990
   </code>
   megabytes. To
explicitly cast the oplog
   <code class="leafygreen-ui-1l06pbn">
    size
   </code>
   in
   <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>
   , use the
   <code class="leafygreen-ui-1l06pbn">
    Double()
   </code>
   constructor.
  </p>
  <p class="leafygreen-ui-1kp3ins">
   The following operation changes the oplog size of the replica set
member to 16 gigabytes, or 16000 megabytes.
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand({replSetResizeOplog: 1, size: Double(16000)})","programmingLanguage":"JavaScript"}
  </script>
  <div class="css-16lmvu9">
   <div class="leafygreen-ui-196mwvg">
    <div class="leafygreen-ui-1b1bvay">
     <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(<!-- -->{<span class="lg-highlight-attr">replSetResizeOplog</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-title lg-highlight-class">Double</span>(<span class="lg-highlight-number">16000</span>)})</td></tr></tbody></table></code></pre>
     <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
      <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
       <div class="leafygreen-ui-xhlipt">
        <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
         <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
         </path>
        </svg>
       </div>
      </button>
     </div>
    </div>
   </div>
  </div>
  <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-oplog" rules="none">
   <colgroup>
    <col/>
   </colgroup>
   <tbody valign="top">
    <tr>
     <td class="leafygreen-ui-17r2xs0">
      [
      <a href="#ref-oplog-id1">
       1
      </a>
      ]
     </td>
     <td class="leafygreen-ui-17r2xs0">
      <!-- -->
      The oplog can grow past its configured size
limit to avoid deleting the
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetGetStatus/#mongodb-data-replSetGetStatus.optimes.lastCommittedOpTime">
       <code class="leafygreen-ui-1l06pbn">
        majority commit point
       </code>
       .
      </a>
     </td>
    </tr>
   </tbody>
  </table>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   D. (Optional) Compact
   <code class="leafygreen-ui-1l06pbn">
    oplog.rs
   </code>
   to reclaim disk space
   <a class="headerlink leafygreen-ui-1kepx47" href="#d.--optional--compact-oplog.rs-to-reclaim-disk-space" 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="d.--optional--compact-oplog.rs-to-reclaim-disk-space">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   Reducing the size of the oplog does
   <em>
    not
   </em>
   automatically reclaim
the disk space allocated to the original oplog size. You must run
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/compact/#mongodb-dbcommand-dbcmd.compact">
    <code class="leafygreen-ui-1l06pbn">
     compact
    </code>
   </a>
   against the
   <code class="leafygreen-ui-1l06pbn">
    oplog.rs
   </code>
   collection in the
   <code class="leafygreen-ui-1l06pbn">
    local
   </code>
   database to reclaim disk space. There are no benefits to
running
   <code class="leafygreen-ui-1l06pbn">
    compact
   </code>
   on the
   <code class="leafygreen-ui-1l06pbn">
    oplog.rs
   </code>
   collection after increasing the
oplog size.
  </p>
  <div class="leafygreen-ui-85da11" role="note">
   <h2 class="leafygreen-ui-1ac4g5h">
    Important
   </h2>
   <div class="leafygreen-ui-9mycqc">
    <p class="leafygreen-ui-1kp3ins">
     A replica set member can replicate oplog entries while the
     <code class="leafygreen-ui-1l06pbn">
      compact
     </code>
     operation is ongoing. As a result, it is no longer necessary to limit
compaction operations on the oplog to maintenance windows, as oplog
replication can continue as normal during compaction.
    </p>
   </div>
  </div>
  <p class="leafygreen-ui-1kp3ins">
   Do
   <strong>
    not
   </strong>
   run
   <code class="leafygreen-ui-1l06pbn">
    compact
   </code>
   against the primary replica set member.
Connect a
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo">
    <code class="leafygreen-ui-1l06pbn">
     mongo
    </code>
   </a>
   shell directly to the primary
(not the replica set) and run
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.stepDown/#mongodb-method-rs.stepDown">
    <code class="leafygreen-ui-1l06pbn">
     rs.stepDown()
    </code>
   </a>
   . If successful,
the primary steps down. From the
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo">
    <code class="leafygreen-ui-1l06pbn">
     mongo
    </code>
   </a>
   shell, run
the
   <code class="leafygreen-ui-1l06pbn">
    compact
   </code>
   command on the now-secondary member.
  </p>
  <p class="leafygreen-ui-1kp3ins">
   The following operation runs the
   <code class="leafygreen-ui-1l06pbn">
    compact
   </code>
   command against the
   <code class="leafygreen-ui-1l06pbn">
    oplog.rs
   </code>
   collection:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"use local\ndb.runCommand({ \"compact\" : \"oplog.rs\" } )","programmingLanguage":"JavaScript"}
  </script>
  <div class="css-16lmvu9">
   <div class="leafygreen-ui-196mwvg">
    <div class="leafygreen-ui-yzcs8i">
     <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">use local</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(<!-- -->{ <span class="lg-highlight-string">"compact"</span> <!-- -->: <span class="lg-highlight-string">"oplog.rs"</span> } )</td></tr></tbody></table></code></pre>
     <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
      <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
       <div class="leafygreen-ui-xhlipt">
        <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
         <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
         </path>
        </svg>
       </div>
      </button>
     </div>
    </div>
   </div>
  </div>
  <p class="leafygreen-ui-1kp3ins">
   For clusters enforcing
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-authentication">
    authentication
   </a>
   ,
authenticate as a user with the
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-compact">
    <code class="leafygreen-ui-1l06pbn">
     compact
    </code>
   </a>
   privilege
action on the
   <code class="leafygreen-ui-1l06pbn">
    local
   </code>
   database and the
   <code class="leafygreen-ui-1l06pbn">
    oplog.rs
   </code>
   collection.
For complete documentation on
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/compact/#mongodb-dbcommand-dbcmd.compact">
    <code class="leafygreen-ui-1l06pbn">
     compact
    </code>
   </a>
   authentication
requirements, see
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/compact/#std-label-compact-authentication">
    <code class="leafygreen-ui-1l06pbn">
     compact
    </code>
    Required Privileges
    <!-- -->
    .
   </a>
  </p>
 </section>
</section>
