Skip to content
Latchkey

mongostat: Usage, Options & Common CI Errors

mongostat prints a rolling view of MongoDB operations per second.

mongostat surfaces inserts, queries, and lock activity for diagnostics. The CI hazard mirrors top: without a row count it runs forever and hangs the job until timeout.

What it does

mongostat polls a MongoDB server at a fixed interval and prints a line of counters (inserts, queries, updates, deletes, connections, network) per tick. It is a live diagnostic, like vmstat for MongoDB.

Common usage

Terminal
mongostat --uri="mongodb://localhost:27017" 2 5   # every 2s, 5 rows
mongostat --uri="mongodb://user:pass@localhost:27017/?authSource=admin" 1 10
mongostat --host 127.0.0.1 --port 27017 --rowcount=3
mongostat --uri="mongodb://localhost:27017" --discover 5 4

Options

ItemWhat it does
<interval>Seconds between samples (positional)
<count> / --rowcount=NStop after N samples
--uri="..."Connection string
--discoverAlso report replica-set/cluster members
-o / --jsonCustom / JSON output

Common errors in CI

Without a row count, mongostat runs until killed and will hang a CI step until the job timeout - always pass a count (the second positional arg) or --rowcount. "Failed: error connecting ... connection refused" means the server is not up; gate on a mongosh ping. Auth uses the same connection-string/authSource rules as mongosh, so admin users need ?authSource=admin.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →