> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# db.serverStatus() (mongosh method)

Returns a [document](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-document) that provides an overview of the database process's state.

This command provides a wrapper around the database command [`serverStatus`.](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#mongodb-dbcommand-dbcmd.serverStatus)

## Compatibility

This method is available in deployments hosted in the following environments:

- [MongoDB Atlas](https://www.mongodb.com/docs/atlas): The fully managed service for MongoDB deployments in the cloud

**Important:**

This command is not supported in M0 and Flex clusters. For more information, see [Unsupported Commands.](https://www.mongodb.com/docs/atlas/unsupported-commands/)

- [MongoDB Enterprise](https://www.mongodb.com/docs/manual/administration/install-enterprise.md#std-label-install-mdb-enterprise): The subscription-based, self-managed version of MongoDB

- [MongoDB Community](https://www.mongodb.com/docs/manual/administration/install-community.md#std-label-install-mdb-community-edition): The source-available, free-to-use, and self-managed version of MongoDB

## Behavior

By default, [`db.serverStatus()`](https://www.mongodb.com/docs/manual/reference/method/db.serverStatus.md#mongodb-method-db.serverStatus) excludes in its output:

- some content in the [repl](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#std-label-server-status-repl) document.

- [mirroredReads](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#std-label-server-status-mirroredReads) document.

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.

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

The following example includes all [repl](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#std-label-server-status-repl) information in the output:

```javascript
db.serverStatus( { repl: 1 } )
```

### Exclude All Optional Fields

Starting in MongoDB 8.3, you can exclude all optional fields from the `db.serverStatus()` output by specifying `none: 1`. After you exclude all optional fields, you can then specify the fields you want to include.

This example uses `none` to initially exclude all optional fields from the output, then includes the  `locks` document.

```javascript
db.serverStatus({ none: 1, locks: 1 })
```

### Initialization

The statistics reported by [`db.serverStatus()`](https://www.mongodb.com/docs/manual/reference/method/db.serverStatus.md#mongodb-method-db.serverStatus) are reset when the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) server is restarted. The [`db.serverStatus()`](https://www.mongodb.com/docs/manual/reference/method/db.serverStatus.md#mongodb-method-db.serverStatus) command does not report some statistics until they have been initialized by server events.

For example, after restarting the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) server, [`db.serverStatus()`](https://www.mongodb.com/docs/manual/reference/method/db.serverStatus.md#mongodb-method-db.serverStatus) won't return any values for `findAndModify`.

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

After you run an update query, subsequent calls to [`db.serverStatus()`](https://www.mongodb.com/docs/manual/reference/method/db.serverStatus.md#mongodb-method-db.serverStatus) display the expected metrics.

```javascript
{
   "arrayFilters" : Long(0),
   "failed" : Long(0),
   "pipeline" : Long(0),
   "total" : Long(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:

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

Returns:

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

### Include `mirroredReads`

By default, the [`mirroredReads`](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#mongodb-serverstatus-serverstatus.mirroredReads) information is not included in the output. To return [`mirroredReads`](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#mongodb-serverstatus-serverstatus.mirroredReads) information, you must explicitly specify the inclusion:

```javascript
db.serverStatus( { mirroredReads: 1 } )
```

## Output

See [serverStatus Output](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#std-label-server-status-output) for complete documentation of the output of this function.
