Docs Menu
Docs Home
/
MongoDB Manual
/ / /

db.serverStatus()

On this page

  • Behavior
  • Output
db.serverStatus()

Returns a document that provides an overview of the database process's state.

This command provides a wrapper around the database command serverStatus.

By default, db.serverStatus() excludes in its output:

  • some content in the repl document.

  • mirroredReads document. (Available starting in version 4.4)

To include fields that are excluded by default, specify the top-level field and set it to 1 in the command. To exclude fields that are included by default, specify the field and set to 0. You can specify either top-level or embedded fields.

For example, the following operation suppresses the repl, metrics and locks information in the output.

db.serverStatus( { repl: 0, metrics: 0, locks: 0 } )

The following example includes all repl information in the output:

db.serverStatus( { repl: 1 } )

The statistics reported by db.serverStatus() are reset when the mongod server is restarted. The db.serverStatus() command does not report some statistics until they have been initialized by server events.

For example, after restarting the mongod server, db.serverStatus() won't return any values for findAndModify.

db.serverStatus().metrics.commands.findAndModify
// No results returned

After you run an update query, subsequent calls to db.serverStatus() display the expected metrics.

{
"arrayFilters" : NumberLong(0),
"failed" : NumberLong(0),
"pipeline" : NumberLong(0),
"total" : NumberLong(1)
}

Note

The db.serverStatus() method returns an error if a specific object is queried before the counters have begun to increment.

If there haven't been any document updates yet:

db.serverStatus().metrics.commands.update.pipeline

Returns:

TypeError: db.serverStatus(...).metrics.commands.update is undefined :
@(shell):1:1

By default, the mirroredReads information (available starting in version 4.4) is not included in the output. To return mirroredReads information, you must explicitly specify the inclusion:

db.serverStatus( { mirroredReads: 1 } )

See serverStatus Output for complete documentation of the output of this function.

Back

db.serverCmdLineOpts()

On this page