How to Shrink the MongoDB 7.0 Oplog

The good news is that in MongoDB 7.0, you don’t have to drop collections or destroy anything to fix this. You can resize it dynamically on the fly without a restart.

Once you have brought the stack up normally (docker compose up -d), follow these steps:

Step 1: Exec into the MongoDB Container

Jump into the container’s interactive shell using mongosh:

docker exec -it dc-rocketchat-mongodb mongosh -u <your_username> -p <your_password> --authenticationDatabase admin

(If you don’t have authentication enabled yet, just run docker exec -it dc-rocketchat-mongodb mongosh)

Step 2: Check your current Oplog size

Switch to the local database and look at the maximum allocation size (displayed in bytes):

use local
db.oplog.rs.stats().maxSize

Step 3: Resize it down

You can safely shrink it down using the replSetResizeOplog command. For a personal or small-team Rocket.Chat setup, 2GB to 5GB is plenty.

To set it to 2048 MB (2 GB), execute this command against the admin database:

db.getSiblingDB("admin").command({ replSetResizeOplog: 1, size: Double(2048) })

You should see a clean { ok: 1 } response.

Step 4: Reclaim the Disk Space (Optional)

Shrinking the limit stops the oplog from growing, but WiredTiger won’t immediately shrink the actual file on your Unraid cache/array. To force MongoDB to truncate the old logs and give the space back to Unraid right away, run a compaction:

use local
db.runCommand({ compact: "oplog.rs" })

(Note: The compaction might momentarily pause replication, but since Rocket.Chat runs on a single-node replica set, it won’t impact anything other than a brief freeze on active chat messages while it drops the old blocks).


If you ever do need to script a Mongo command anyway…

If you ever find a legitimate reason to script database commands on Unraid (like forcing a weekly backup or clearing cache), you can do it seamlessly from the Unraid terminal or via the User Scripts plugin by piping JavaScript directly into mongosh inside the container:

# Example syntax for an automated script
docker exec -i dc-rocketchat-mongodb mongosh --quiet admin --eval '
  db.getSiblingDB("admin").command({ replSetResizeOplog: 1, size: Double(2048) });
'

<strong>docker exec -it dc-rocketchat-mongodb mongosh</strong>
Current Mongosh Log ID:	6a398a4dbed381329e9df8a2
Connecting to:		mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.8.3
Using MongoDB:		7.0.37
Using Mongosh:		2.8.3

For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/

------
   The server generated these startup warnings when booting
   2026-06-22T15:16:54.972-04:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
   2026-06-22T15:16:54.972-04:00: Soft rlimits for open file descriptors too low
   2026-06-22T15:16:54.972-04:00: For customers running MongoDB 7.0, we suggest changing the contents of the following sysfsFile
   2026-06-22T15:16:55.720-04:00: Document(s) exist in 'system.replset', but started without --replSet. Database contents may appear inconsistent with the writes that were visible when this node was running as part of a replica set. Restart with --replSet unless you are doing maintenance and no other clients are connected. The TTL collection monitor will not start because of this. For more info see http://dochub.mongodb.org/core/ttlcollections
   2026-06-22T15:16:55.720-04:00: Replica set member is in standalone mode. Performing any writes will result in them being untimestamped. If a write is to an existing document, the document's history will be overwritten with the new value since the beginning of time. This can break snapshot isolation within the storage engine.
------

Warning: Found ~/.mongorc.js, but not ~/.mongoshrc.js. ~/.mongorc.js will not be loaded.
  You may want to copy or rename ~/.mongorc.js to ~/.mongoshrc.js.
test> <strong>use local</strong>
switched to db local
local> <strong>db.system.replset.update({}, { $set: { repaired: false } })</strong>
DeprecationWarning: Collection.update() is deprecated. Use updateOne, updateMany, or bulkWrite.
{
  acknowledged: true,
  insertedId: null,
  matchedCount: 1,
  modifiedCount: 1,
  upsertedCount: 0
}
local> <strong>db.runCommand({ compact: "oplog.rs" })</strong>
{ bytesFreed: 0, ok: 1 }
local> rs.printReplicationInfo()
actual oplog size
'40316.378710746765 MB'
---
configured oplog size
'40316.378710746765 MB'
---
log length start to end
'173912179 secs (48308.94 hrs)'
---
oplog first event time
'Sun Dec 06 2020 16:54:07 GMT-0500 (Eastern Standard Time)'
---
oplog last event time
'Thu Jun 11 2026 14:50:26 GMT-0400 (Eastern Daylight Time)'
---
now
'Mon Jun 22 2026 15:19:57 GMT-0400 (Eastern Daylight Time)'
local> db.getSiblingDB("admin").command({ replSetResizeOplog: 1, size: Double(2048) })
TypeError: db.getSiblingDB("admin").command is not a function
local> <strong>db.adminCommand({ replSetResizeOplog: 1, size: 2048 })</strong>
{ ok: 1 }
local> <strong>rs.printReplicationInfo()</strong>
actual oplog size
'5560.758267402649 MB'
---
configured oplog size
'2048 MB'
---
log length start to end
'173912179 secs (48308.94 hrs)'
---
oplog first event time
'Sun Dec 06 2020 16:54:07 GMT-0500 (Eastern Standard Time)'
---
oplog last event time
'Thu Jun 11 2026 14:50:26 GMT-0400 (Eastern Daylight Time)'
---
now
'Mon Jun 22 2026 15:22:57 GMT-0400 (Eastern Daylight Time)'
local> <strong>db.runCommand({ compact: "oplog.rs" })</strong>
{ bytesFreed: 0, ok: 1 }
local> <strong>db.oplog.rs.storageSize() / 1024 / 1024</strong>
1113.09375

Leave a Reply