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

# hello (database command)

## Definition

**New in version 4.2**

[`hello`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-dbcommand-dbcmd.hello) returns a document that describes the role of the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) instance. If the optional field `saslSupportedMechs` is specified, the command also returns an [`array of SASL mechanisms`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-data-hello.saslSupportedMechs) used to create the specified user's credentials.

If the instance is a member of a replica set, then [`hello`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-dbcommand-dbcmd.hello) returns a subset of the replica set configuration and status including whether or not the instance is the [primary](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-primary) of the replica set.

When sent to a [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) instance that is not a member of a replica set, [`hello`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-dbcommand-dbcmd.hello) returns a subset of this information.

MongoDB [drivers](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-driver) and [clients](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-client) use [`hello`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-dbcommand-dbcmd.hello) to determine the state of the replica set members and to discover additional members of a [replica set.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-replica-set)

## Compatibility

This command 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

**Note:**

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, 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

## Syntax

The command has the following syntax:

```javascript
db.runCommand(
   {
     hello: 1
   }
)
```

The [`hello`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-dbcommand-dbcmd.hello) command accepts optional fields `saslSupportedMechs: <db.user>` to return an additional field [`hello.saslSupportedMechs`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-data-hello.saslSupportedMechs) in its result and `comment <any>` to add a log comment associated with the command.

```javascript
db.runCommand(
   {
     hello: 1,
     saslSupportedMechs: "<db.username>",
     comment: <any>
   }
)
```

The [`db.hello()`](https://www.mongodb.com/docs/manual/reference/method/db.hello.md#mongodb-method-db.hello) method in [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) provides a wrapper around [`hello`.](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-dbcommand-dbcmd.hello)

## Behavior

### Client Disconnection

If the client that issued [`hello`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-dbcommand-dbcmd.hello) disconnects before the operation completes, MongoDB marks [`hello`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-dbcommand-dbcmd.hello) for termination using [`killOp`.](https://www.mongodb.com/docs/manual/reference/command/killOp.md#mongodb-dbcommand-dbcmd.killOp)

## Output

### All Instances

The following [`hello`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-dbcommand-dbcmd.hello) fields are common across all roles:

A boolean value that reports when this node is writable. If `true`, then this instance is a [primary](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-primary) in a [replica set](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-replica-set), or a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance, or a standalone [`mongod`.](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod)

This field will be `false` if the instance is a [secondary](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-secondary) member of a replica set or if the member is an [arbiter](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-arbiter) of a replica set.

*For internal use by MongoDB.*

The maximum permitted size of a [BSON](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-BSON) object in bytes for this [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) process. If not provided, clients should assume a max size of "`16 * 1024 * 1024`".

The maximum permitted size of a [BSON](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-BSON) wire protocol message. The default value is `48000000` bytes.

The maximum number of write operations permitted in a write batch. If a batch exceeds this [limit](https://www.mongodb.com/docs/manual/reference/limits.md#mongodb-limit-Write-Command-Batch-Limit-Size), the client driver divides the batch into smaller groups each with counts less than or equal to the value of this field.

The value of this limit is `100,000` writes.

Returns the local server time in UTC. This value is an [ISO date.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-ISODate)

The time in minutes that a [session](https://www.mongodb.com/docs/manual/core/read-isolation-consistency-recency.md#std-label-sessions) remains active after its most recent use. Sessions that have not received a new read/write operation from the client or been refreshed with [`refreshSessions`](https://www.mongodb.com/docs/manual/reference/command/refreshSessions.md#mongodb-dbcommand-dbcmd.refreshSessions) within this threshold are cleared from the cache. State associated with an expired session may be cleaned up by the server at any time.

Only available when `featureCompatibilityVersion` is `"3.6"` or greater.

An identifier for the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) / [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance's outgoing connection to the client.

The earliest version of the wire protocol that this [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) or [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance is capable of using to communicate with clients.

Clients may use [`minWireVersion`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-data-hello.minWireVersion) to help negotiate compatibility with MongoDB.

The latest version of the wire protocol that this [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) or [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance is capable of using to communicate with clients.

Clients may use [`maxWireVersion`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-data-hello.maxWireVersion) to help negotiate compatibility with MongoDB.

A boolean value that, when `true`, indicates that the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) or [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) is running in read-only mode.

An array listing the compression algorithms used or available for use (i.e. common to both the client and the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) or [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance) to compress the communication between the client and the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) or [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance.

The field is only available if compression is used. For example:

- If the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) is enabled to use both the `snappy,zlib` compressors and a client has specified `zlib`, the [`compression`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-data-hello.compression) field would contain:

  ```javascript
  "compression": [ "zlib" ]
  ```

- If the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) is enabled to use both the `snappy,zlib` compressors and a client has specified `zlib,snappy`, the [`compression`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-data-hello.compression) field would contain:

  ```javascript
  "compression": [ "zlib", "snappy" ]
  ```

- If the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) is enabled to use  the `snappy` compressor and a client has specified `zlib,snappy`, the [`compression`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-data-hello.compression) field would contain :

  ```javascript
  "compression": [ "snappy" ]
  ```

- If the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) is enabled to use  the `snappy` compressor and a client has specified `zlib` or the client has specified no compressor, the field is omitted.

That is, if the client does not specify compression or if the client specifies a compressor not enabled for the connected [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) or [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance, the field does not return.

An array of SASL mechanisms used to create the user's credential or credentials.  Supported SASL mechanisms are:

- `GSSAPI`

- `SCRAM-SHA-256`

- `SCRAM-SHA-1`

The field is returned only when the command is run with the `saslSupportedMechs` field:

```javascript
db.runCommand( { hello: 1, saslSupportedMechs: "<db.username>" } )
```

### Sharded Instances

[`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances add the following field to the [`hello`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-dbcommand-dbcmd.hello) response document:

Contains the value `isdbgrid` when [`hello`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-dbcommand-dbcmd.hello) returns from a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance.

### Replica Sets

[`hello`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-dbcommand-dbcmd.hello) contains these fields when returned by a member of a replica set:

An array of strings in the format of `"[hostname]:[port]"` that lists all members of the [replica set](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-replica-set) that are neither [hidden](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-hidden-member), [passive](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-passive-member), nor [arbiters.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-arbiter)

Drivers use this array and the [`hello.passives`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-data-hello.passives) to determine which members to read from.

The name of the current :replica set.

The current replica set config version.

A boolean value that, when `true`, indicates if the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) is a [secondary](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-secondary) member of a [replica set.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-replica-set)

An array of strings in the format of `"[hostname]:[port]"` listing all members of the [replica set](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-replica-set) which have a [`members[n].priority`](https://www.mongodb.com/docs/manual/reference/replica-configuration.md#mongodb-rsconf-rsconf.members-n-.priority) of `0`.

This field only appears if there is at least one member with a [`members[n].priority`](https://www.mongodb.com/docs/manual/reference/replica-configuration.md#mongodb-rsconf-rsconf.members-n-.priority) of `0`.

Drivers use this array and the [`hello.hosts`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-data-hello.hosts) to determine which members to read from.

An array of strings  in the format of `"[hostname]:[port]"` listing all members of the [replica set](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-replica-set) that are [arbiters.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-arbiter)

This field only appears if there is at least one arbiter in the replica set.

A string in the format of `"[hostname]:[port]"` listing the current [primary](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-primary) member of the replica set.

A boolean value that , when `true`, indicates that the current instance is an [arbiter](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-arbiter).  The [`arbiterOnly`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-data-hello.arbiterOnly) field is only present, if the instance is an arbiter.

A boolean value that, when `true`, indicates that the current instance is [passive](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-passive-member).  The [`passive`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-data-hello.passive) field is only present for members with a [`members[n].priority`](https://www.mongodb.com/docs/manual/reference/replica-configuration.md#mongodb-rsconf-rsconf.members-n-.priority) of `0`.

A boolean value that, when `true`, indicates that the current instance is [hidden](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-hidden-member).  The [`hidden`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-data-hello.hidden) field is only present for hidden members.

A `tags` document contains user-defined tag field and value pairs for the replica set member.

```javascript
{ "<tag1>": "<string1>", "<tag2>": "<string2>",... }
```

- For read operations, you can specify a tag set in the [read preference](https://www.mongodb.com/docs/manual/core/read-preference-tags.md#std-label-replica-set-read-preference-tag-sets) to direct the operations to replica set member(s) with the specified tag(s).

- For write operations, you can create a customize [write concern](https://www.mongodb.com/docs/manual/reference/write-concern.md) using [`settings.getLastErrorModes`](https://www.mongodb.com/docs/manual/reference/replica-configuration.md#mongodb-rsconf-rsconf.settings.getLastErrorModes) and [`settings.getLastErrorDefaults`.](https://www.mongodb.com/docs/manual/reference/replica-configuration.md#mongodb-rsconf-rsconf.settings.getLastErrorDefaults)

For more information, see [Configure Replica Set Tag Sets.](https://www.mongodb.com/docs/manual/tutorial/configure-replica-set-tag-sets.md#std-label-replica-set-configuration-tag-sets)

**See also:**

[`members[n].tags`](https://www.mongodb.com/docs/manual/reference/replica-configuration.md#mongodb-rsconf-rsconf.members-n-.tags)

The `[hostname]:[port]` of the member that returned [`hello`.](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-dbcommand-dbcmd.hello)

A unique identifier for each election. Included only in the output of [`hello`](https://www.mongodb.com/docs/manual/reference/command/hello.md#mongodb-dbcommand-dbcmd.hello) for the [primary](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-primary). Used by clients to determine when elections occur.

A document containing [optime](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-optime) and date information for the database's most recent write operation.

An object giving the [optime](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-optime) of the last write operation.

A date object containing the time of the last write operation.

An object giving the [optime](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-optime) of the last write operation readable by [`majority`](https://www.mongodb.com/docs/manual/reference/read-concern-majority.md#mongodb-readconcern-readconcern.-majority-) reads.

A date object containing the time of the last write operation readable by [`majority`](https://www.mongodb.com/docs/manual/reference/read-concern-majority.md#mongodb-readconcern-readconcern.-majority-) reads.

For details on the `ok` status field, the `operationTime` field, and the `$clusterTime` field, see [Command Response.](https://www.mongodb.com/docs/manual/reference/method/db.runCommand.md#std-label-command-response)
