<!-- llms-explorer concept facts · https://llms-explorer.com/tree/mongodb-sharded-query-targeting/ · pack 2026-10-19 · ~34828 tokens -->

# MongoDB sharded query targeting and scatter-gather

> Everything the scanned sources say about MongoDB sharded query targeting and scatter-gather: 361 source-anchored units across 1 sources, grouped by facet.

Parent: [Global AI Hub Research Corpus](https://llms-explorer.com/tree/global-ai-hub-research-corpus/) · 9 facets · 361 facts · page: https://llms-explorer.com/tree/mongodb-sharded-query-targeting/

## Definitions

- However, hashed distribution means that range-based queries on the shard key are less likely to target a single shard, resulting in more cluster-wide broadcast operations. — [source](https://www.mongodb.com/docs/manual/sharding/)

## Structure and components

- 2. Before creating the index, validate that no documents in the collection violate the index constraints. If a collection is distributed across shards and a shard contains a chunk with duplicate documents, the create index operation may succeed on the shards without duplicates but not on the shard with duplicates. To avoid leaving inconsistent indexes across shards, you can issue the [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) from a [`mongos`](https://www.mongodb.com/docs/manual/reference — [source](https://www.mongodb.com/docs/manual/tutorial/build-indexes-on-sharded-clusters.md#before-you-begin)
- When run on mongos, indexes can only cover queries on sharded collections if the index contains the shard key. — [source](https://www.mongodb.com/docs/manual/core/query-optimization/)
- Contains information on the selection of the query plan by the [query optimizer.](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-read-operations-query-optimization) — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- If query settings are set, `querySettings` contains details about the query settings that are applied to the query shape. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- When run on a `mongos` that is part of a sharded cluster: — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp.md#sharded-cluster-mongos-query-analyzer-output)
- As part of establishing a TCP Fast Open (TFO) connection, the client submits a valid TFO cookie to the `mongod/mongos` *before* completion of the standard TCP 3-way handshake. The `mongod/mongos` keeps a queue of all such pending TFO connections. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#general-parameters)
- Configures a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance to preload the routing table for a sharded cluster on startup. With this setting enabled, the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) caches the cluster-wide routing table for each sharded collection as part of its startup procedure, before it begins accepting client connections. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- Configures a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance to prewarm its connection pool on startup. With this parameter enabled, the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) attempts to establish [`ShardingTaskExecutorPoolMinSize`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.ShardingTaskExecutorPoolMinSize) network connections to each shard server as part of its startup procedure, before it begins accepting client connections. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#error-response)
- | Name | Type | Required | Description | | --- | --- | --- | --- | | --apiKey | string | false | Datadog API Key, Opsgenie API Key, or VictorOps API key. Required if the notificationType is DATADOG, OPS_GENIE, or VICTOR_OPS, respectively. | | --enabled | | false | Flag that indicates whether to enable the alert configuration. | | --event | string | false | Type of event that triggered the alert. To learn which values the CLI accepts, see the Enum for eventTypeName in the Atlas Admin API spec: [https://dochub.mongodb.org/core/atlas-event-names.](https://dochub.mongodb.org/core/atlas-event-name — [source](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-alerts-settings-create.md#options)
- A document that contains metrics about [`mongos`.](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#metrics)
- The total number of logical bytes that `mongod` or `mongos` instances have *received* over network connections that they have initiated to other nodes/services. Logical bytes are the exact number of bytes that a given file contains. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#network)
- The total number of logical bytes that `mongod` or `mongos` instances have *sent* over network connections that they have initiated to other nodes/services. Logical bytes correspond to the number of bytes that a given file contains. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#network)
- The total number of logical bytes that the server has *received* over network connections initiated by clients or other `mongod` or `mongos` instances. Logical bytes are the exact number of bytes that a given file contains. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#network)
- The total number of logical bytes that the server has *sent* over network connections initiated by clients or other `mongod` or `mongos` instances. Logical bytes correspond to the number of bytes that a given file contains. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#network)
- Total number of network requests targeted by the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) as part of its transactions. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#mongod)
- A list of IP addresses/CIDR ([Classless Inter-Domain Routing](https://tools.ietf.org/html/rfc4632)) ranges against which the `mongod` validates authentication requests from other members of the replica set and, if part of a sharded cluster, the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances. The `mongod` verifies that the originating IP is either explicitly in the list or belongs to a CIDR range in the list. If the IP address is not present, the server does not authenticate the `mongod` or [`mongos`.](https://www.mongodb.com/docs — [source](https://www.mongodb.com/docs/manual/reference/program/mongod.md#core-options)
- - Deploy [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) routers in accordance with the [Production Configuration](https://www.mongodb.com/docs/manual/core/sharded-cluster-components.md#std-label-sc-production-configuration) guidelines. — [source](https://www.mongodb.com/docs/manual/administration/production-checklist-operations.md#sharding)
- | Aspect | Atlas Core | Atlas Infinite | | --- | --- | --- | | Architecture | Compute and storage run on the same node. Each data-bearing node runs on a virtual machine with attached storage. | Compute and storage run as independent layers. MongoDB manages the storage layer separately from the compute nodes. | | Compute scaling | You change compute capacity by selecting a different cluster tier. Atlas restarts the cluster's nodes when you change the tier, with no downtime on dedicated clusters. | You scale the cluster tier independently of storage. Scaling doesn't move your data, so it is fast — [source](https://www.mongodb.com/docs/atlas/index.md#compare-editions)
- Messages related to sharding activities, such as the startup of the mongos. To specify the log level for SHARDING components, use the systemLog.component.sharding.verbosity setting. — [source](https://www.mongodb.com/docs/manual/reference/log-messages/)
- In some cases, when the shard key or a prefix of the shard key is a part of the query, the mongos performs a targeted operation, routing queries to a subset of shards in the cluster. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- A range of shard keys whose values are "close" are more likely to reside on the same chunk. This allows for targeted operations as a mongos can route the operations to only the shards that contain the required data. — [source](https://www.mongodb.com/docs/manual/sharding/)
- The most common practice is to run `mongos` instances on the same systems as your application servers, but you can maintain `mongos` instances on the shards or on other dedicated resources. See also [Number of `mongos` and Distribution.](https://www.mongodb.com/docs/manual/core/sharded-cluster-components.md#std-label-sharded-cluster-components-distribution) — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md)

## How it works

- When a shard receives a query, it uses the most efficient index available to fulfill that query. The index used may be either the [shard key index](https://www.mongodb.com/docs/manual/core/sharding-shard-key-indexes.md#std-label-sharding-shard-key-indexes) or another eligible index present on the shard. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#index-use)
- Each index suggestion includes an Average Query Targeting score indicating how many documents were read for every document returned for the index's corresponding query shapes. A score of 1 represents very efficient query shapes because every document read matched the query and was returned with the query results. All suggested indexes represent an opportunity to improve query performance. — [source](https://www.mongodb.com/docs/atlas/performance-advisor.md#query-targeting)
- When you use `$sort` on a sharded cluster, each shard sorts its result documents using an index where available. Then the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) or one of the shards performs a streamed merge sort. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort.md#sort-index-use)
- - Create the indexes that the Performance Advisor suggests when they align with your [Indexing Strategies.](https://www.mongodb.com/docs/manual/applications/indexes/) — [source](https://www.mongodb.com/docs/atlas/analyze-slow-queries.md#best-practices-for-query-performance)
- As with any hash function, two different plan cache query shapes may result in the same hash value. However, the occurrence of hash collisions between different plan cache query shapes is unlikely. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- After the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) receives responses from all shards, it merges the data and returns the result document. The performance of a broadcast operation depends on the overall load of the cluster, as well as variables like network latency, individual shard load, and number of documents returned per shard. Whenever possible, favor operations that result in [targeted operation](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#std-label-sharding-mongos-targeted) over those that result i — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#broadcast-operations)
- mongos performs a targeted operation when the query includes the shard key or a prefix of a compound shard key. For key {a:1,b:1,c:1} the usable prefixes are {a:1} and {a:1,b:1}. A query on {b:1} alone is not a prefix and broadcasts. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- When run without [localOps:true](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentop.md#std-label-currentOp-stage-localOps) on the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), the transaction information is per shard. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp.md#mongos-composite-view-output)
- When run on a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) without [localOps:true](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentop.md#std-label-currentOp-stage-localOps), the transaction information is per shard. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp.md#mongos-per-shard-output)
- Not available when running with `localOps: true` on [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) or when reporting on `idleCursors`. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp.md#output-fields)
- Not available when running with `localOps: true` on [`mongos`.](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp.md#output-fields)
- Only reported when running `$currentOp` on `mongos`. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp.md#output-fields)
- When connected to a sharded cluster through [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), you can run the [`profile`](https://www.mongodb.com/docs/manual/reference/command/profile.md#mongodb-dbcommand-dbcmd.profile) command against any database. — [source](https://www.mongodb.com/docs/manual/reference/command/profile.md#behavior)
- The maximum number of seconds that 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) should wait for the OCSP response when verifying server certificates. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#oidcidentityproviders-fields)
- A [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance with the [`loadRoutingTableOnStartup`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.loadRoutingTableOnStartup) parameter enabled may experience longer startup times, but will result in faster servicing of initial client connections once started. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- When a query accesses a shard, a [chunk migration](https://www.mongodb.com/docs/manual/tutorial/migrate-chunks-in-sharded-cluster.md#std-label-migrate-chunks-sharded-cluster) or [DDL operation](https://www.mongodb.com/docs/manual/core/transactions-operations.md#std-label-transactions-operations-ddl) may already hold the critical section for the collection. If the query finds the critical section is taken, the shard waits until the critical section has been released. When the shard returns control to [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.m — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- A [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance with this parameter enabled may experience longer startup times, but will result in faster servicing of initial client connections once started. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#error-response)
- A MongoDB process can be either a mongod or mongos. — [source](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-api-monitoringAndLogs-listGroupProcesses.md)
- When aggregation operations run on multiple shards, the results are routed to the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) to be merged, except in the following cases: — [source](https://www.mongodb.com/docs/manual/core/aggregation-pipeline-sharded-collections.md#behavior)
- You can also [export logs to an AWS S3 bucket](https://www.mongodb.com/docs/atlas/export-logs-external-sinks/). When you configure this feature, Atlas exports from `mongod`, `mongos`, and audit logs to an AWS (Amazon Web Services) S3 bucket every minute. — [source](https://www.mongodb.com/docs/atlas/architecture/current/monitoring-alerts.md#monitor-by-using-logs)
- The current MongoDB process. Possible values are: [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) or [`mongod`.](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#instance-information)
- A document that reports process-level counters for the [`$changeStream`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/changestream.md#mongodb-pipeline-pipe.-changeStream) options set on opened change streams. These counters are tracked on both [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) and [`mongos`.](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#metrics)
- A document that reports the number of change streams opened on this process, categorized by the scope that the change stream watches. These counters are tracked on both [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) and [`mongos`.](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#metrics)
- - The number of times a given authentication mechanism has been used to authenticate against 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. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#security)
- A document that reports on the number of times a given authentication mechanism has been used to authenticate against 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 values in the document distinguish standard authentication and speculative authentication.&#x20; — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#security)
- The fields in the `mechanisms` document depend on the configuration of the [`authenticationMechanisms`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.authenticationMechanisms) parameter. The `mechanisms` document includes a field for each authentication mechanism supported by your [`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. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#security)
- - `true` when 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 TLS/SSL certificate is associated with a certificate authority. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#security)
- When run on a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), a document with data about the [transactions](https://www.mongodb.com/docs/manual/core/transactions.md#std-label-transactions) run on the instance. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#mongod)
- When inserting documents with monotonically increasing shard keys, all inserts belong to the same [chunk](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-chunk) on a single [shard](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-shard). The system eventually divides the chunk range that receives all write operations and migrates its contents to distribute data more evenly. However, at any moment the cluster directs insert operations only to a single shard, which creates an insert throughput bottleneck. — [source](https://www.mongodb.com/docs/manual/reference/limits.md#shard-key-limitations)
- - [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) includes a [Full Time Diagnostic Data Capture](https://www.mongodb.com/docs/manual/administration/full-time-diagnostic-data-capture.md#std-label-ftdc-stub) mechanism to assist MongoDB engineers with troubleshooting deployments. If this thread fails, it terminates the originating process. To avoid the most common failures, confirm that the user running the process has permissions to create the FTDC `diagnostic.data` directory. For `mongod` the directory is within [`storage.dbPath`](https://ww — [source](https://www.mongodb.com/docs/manual/reference/program/mongod.md#considerations)
- Specifies a file location to store the process ID (PID) of the `mongod` process. The user running the `mongod` or `mongos` process must be able to write to this path. If the [`--pidfilepath`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--pidfilepath) option is not specified, the process does not create a PID file. Use this option mainly with the [`--fork`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--fork) option. — [source](https://www.mongodb.com/docs/manual/reference/program/mongod.md#core-options)
- Allows the `mongod` to accept and create authenticated and non-authenticated connections to and from other `mongod` and [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances in the deployment. Used for performing rolling transition of replica sets or sharded clusters from a no-auth configuration to [internal authentication](https://www.mongodb.com/docs/manual/core/security-internal-authentication.md#std-label-inter-process-auth). Requires specifying a [internal authentication](https://www.mongodb.com/docs/manual/core/security-internal-a — [source](https://www.mongodb.com/docs/manual/reference/program/mongod.md#core-options)
- For example, if using [keyfiles](https://www.mongodb.com/docs/manual/core/security-internal-authentication.md#std-label-internal-auth-keyfile) for [internal authentication](https://www.mongodb.com/docs/manual/core/security-internal-authentication.md#std-label-inter-process-auth), the `mongod` creates an authenticated connection with any `mongod` or [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) in the deployment using a matching keyfile. If the security mechanisms do not match, the `mongod` uses a non-authenticated connection instead. — [source](https://www.mongodb.com/docs/manual/reference/program/mongod.md#core-options)
- The [config database](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-config-database) maintains a map identifying which documents are on which shards. The cluster updates this map as [chunks](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-chunk) move between shards. When a configuration server becomes inaccessible, certain sharding operations become unavailable, such as moving chunks and starting [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances. However, clusters remain accessible from alread — [source](https://www.mongodb.com/docs/manual/administration/monitoring.md#config-servers)
- Because inaccessible configuration servers can seriously impact the availability of a sharded cluster, you should monitor your configuration servers to ensure that the cluster remains well balanced and that [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances can restart. — [source](https://www.mongodb.com/docs/manual/administration/monitoring.md#config-servers)
- When run on a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), [`$currentOp`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentop.md#mongodb-pipeline-pipe.-currentOp) returns the opids in the format of `"<shardName>:<opid on that shard>"`; e.g. — [source](https://www.mongodb.com/docs/manual/reference/method/db.killOp.md#kill-write-operations)
- In sharded clusters, MongoDB records query statistics separately on each mongod and mongos when $queryStats is enabled. Shard servers also record statistics for queries that originate from mongos. These provide more complete shard-level metrics for queries that users route through mongos. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/)
- When a user creates a session on a [`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 record of the session initially exists only in-memory on the instance; i.e. the record is local to the instance. Periodically, the instance will sync its cached sessions to the [`system.sessions`](https://www.mongodb.com/docs/manual/reference/config-database.md#mongodb-data-config.system.sessions) collection in the `config` database, at which — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions.md#definition)
- Hashed indexing is ideal for shard keys with fields that change [monotonically](https://www.mongodb.com/docs/manual/core/sharding-choose-a-shard-key.md#std-label-shard-key-monotonic) like [ObjectId](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-ObjectId) values or timestamps. When you use [ranged sharding](https://www.mongodb.com/docs/manual/core/ranged-sharding.md#std-label-sharding-ranged) with a monotonically increasing shard key value, the chunk with an upper bound of [`MaxKey`](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json.md#mongodb-bsontype-Max — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-hashed.md#use-cases)
- mongos performs a broadcast operation for queries that do not include the shard key, routing queries to all shards in the cluster. Some queries that do include the shard key may still result in a broadcast operation depending on the distribution of data in the cluster and the selectivity of the query. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- With RBAC enforced, clients must specify a --username, --password, and --authenticationDatabase when connecting to the mongos in order to access cluster resources. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- - MongoDB Compass shows limited performance data when connected to a [`mongos`.](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) — [source](https://www.mongodb.com/docs/compass/performance.md#limitations)

## How-to and procedures

- To improve query performance for [time series collections](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-time-series-collection), add one or more [secondary indexes](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-secondary-index) to support common time series query patterns. Starting in MongoDB 6.3, MongoDB automatically creates a [compound index](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound.md#std-label-index-type-compound) on the `metaField` and `timeField` fields for new collections. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md)
- To improve query performance, [create one or more secondary indexes](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#std-label-timeseries-add-secondary-index) on your `timeField` and `metaField` to support common query patterns. In versions 6.3 and higher, MongoDB creates a secondary index on the `timeField` and `metaField` automatically. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-best-practices.md#create-secondary-indexes)
- To analyze query performance, see [Interpret Explain Plan Results.](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md) — [source](https://www.mongodb.com/docs/manual/core/query-optimization.md#create-indexes-to-support-queries)
- To view the MongoDB 8.0 `queryShapeHash` and `planCacheShapeHash` hexadecimal strings, you can use the [`explain`](https://www.mongodb.com/docs/manual/reference/command/explain.md#mongodb-dbcommand-dbcmd.explain) command. — [source](https://www.mongodb.com/docs/manual/core/query-shapes.md#matching-query-shapes)
- To enable log redaction on a running `mongod` or `mongos`, use the following command: — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#logging-parameters)
- To avoid this, users should connect to single-shard clusters through a router, like `mongos`. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- To make this setting persistent, set `activeFaultDurationSecs` in your [mongos config file](https://www.mongodb.com/docs/manual/reference/configuration-options.md#std-label-configuration-options) using the [`setParameter`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-setParameter) option as in the following example: — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#health-manager-parameters)
- To make this setting persistent, set `healthMonitoringIntensities` in your [mongos config file](https://www.mongodb.com/docs/manual/reference/configuration-options.md#std-label-configuration-options) using the [`setParameter`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-setParameter) option as in the following example: — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#intensity-levels)
- To make this setting persistent, set `healthMonitoringIntervals` in your [mongos config file](https://www.mongodb.com/docs/manual/reference/configuration-options.md#std-label-configuration-options) using the [`setParameter`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-setParameter) option as in the following example: — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#health-managers)
- To make this setting persistent, set `progressMonitor` in your [mongos config file](https://www.mongodb.com/docs/manual/reference/configuration-options.md#std-label-configuration-options) using the [`setParameter`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-setParameter) option as in the following example: — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#progressmonitor-fields)
- Ensure [`--clusterIpSourceAllowlist`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--clusterIpSourceAllowlist) includes the IP address *or* CIDR ranges that include the IP address of each replica set member or [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) in the deployment to ensure healthy communication between cluster components. — [source](https://www.mongodb.com/docs/manual/reference/program/mongod.md#core-options)
- To check the lock status of the database, connect to a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance using [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh). Issue the following command sequence to switch to the `config` database and display all outstanding locks on the shard database: — [source](https://www.mongodb.com/docs/manual/administration/monitoring.md#stale-locks)
- To detect if the MongoDB instance that your client is connected to is mongos, use the hello command. When a client connects to a mongos, hello returns a document with a msg field that holds the string isdbgrid. For example: — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- Use Self-Managed Internal/Membership Authentication to enforce intra-cluster security and prevent unauthorized cluster components from accessing the cluster. You must start each mongod or mongos in the cluster with the appropriate security settings in order to enforce internal authentication. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- Avoid overloading the connection resources of a [`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 by adjusting the connection pool size to suit your use case. Start at 110-115% of the typical number of current database requests, and modify the connection pool size as needed. Refer to the [Connection Pool Options](https://www.mongodb.com/docs/manual/reference/connection-string-options.md#std-label-connection-pool-options) for adjus — [source](https://www.mongodb.com/docs/manual/administration/production-notes.md#manage-connection-pool-sizes)
- To achieve an even data distribution across all shards in the cluster, a balancer runs in the background to migrate ranges across the shards. — [source](https://www.mongodb.com/docs/manual/sharding/)
- to a shard. Please connect to the cluster via a router (mongos)." — [source](https://www.mongodb.com/docs/manual/sharding/)
- To run a non-supported database command directly against a node in a sharded cluster, you must either connect to mongos or have the maintenance-only directShardOperations role. — [source](https://www.mongodb.com/docs/manual/sharding/)

## Examples and snippets

- ```javascript — `db.runCommand(` … — [source](https://www.mongodb.com/docs/manual/reference/command/planCacheSetFilter.md#set-filter-on-plan-cache-query-shape-consisting-of-predicate-only)
- ```javascript — `db.runCommand(` … — [source](https://www.mongodb.com/docs/manual/reference/command/planCacheSetFilter.md#set-filter-on-plan-cache-query-shape-consisting-of-predicate-and-collation)
- ```javascript — `db.pizzaOrders.explain().find(` … — [source](https://www.mongodb.com/docs/manual/core/query-shapes.md#matching-query-shapes)
- ```javascript — `db.pizzaOrders.explain().find(` … — [source](https://www.mongodb.com/docs/manual/core/query-shapes.md#different-query-shape)
- ```javascript&#xA;:copyable:false — `"desc" : "query analyzer",` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp.md#sharded-cluster-mongos-query-analyzer-output)
- ```bash — `mongos --setParameter globalConnPoolIdleTimeoutMinutes=10` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#general-parameters)
- ```bash — `mongos --setParameter httpVerboseLogging=true` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#general-parameters)
- ```bash — `mongod --setParameter abortStreamingHelloWithSmallTimeout=true` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#replication-and-consistency)
- ```bash — `mongod --setParameter minWaitForStreamingHelloMillis=1000` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#replication-and-consistency)
- ```bash — `mongod --setParameter enableFinerGrainedCatalogCacheRefresh=true` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- ```bash — `mongos --setParameter findShardsOnConfigTimeoutMS=30000` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- ```bash — `mongos --setParameter mongosShutdownTimeoutMillisForSignaledShutdown=250` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- ```bash — `mongos --setParameter queryAnalysisSamplerConfigurationRefreshSecs=60` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- ```bash — `mongos --setParameter ShardingTaskExecutorPoolHostTimeoutMS=120000` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- ```bash — `mongos --setParameter ShardingTaskExecutorPoolMaxConnecting=20` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- ```bash — `mongos --setParameter ShardingTaskExecutorPoolMaxSize=20` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- ```bash — `mongos --setParameter ShardingTaskExecutorPoolMaxQueueDepth=10` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- ```bash — `mongos --setParameter ShardingTaskExecutorPoolMaxSizeForConfigServers=2` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- ```bash — `mongos --setParameter ShardingTaskExecutorPoolMinSize=2` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- ```bash — `mongos --setParameter ShardingTaskExecutorPoolMinSizeForConfigServers=2` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- ```bash — `mongos --setParameter ShardingTaskExecutorPoolRefreshRequirementMS=90000` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- ```bash — `mongos --setParameter ShardingTaskExecutorPoolRefreshTimeoutMS=30000` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- ```bash — `mongos --setParameter taskExecutorPoolSize=6` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- ```bash — `mongos --setParameter activeFaultDurationSecs=300` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#health-manager-parameters)
- ```bash — `mongos --setParameter 'healthMonitoringIntensities={ values:[ { type:"dns", intensity: "critical"} ] }'` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#intensity-levels)
- ```bash — `mongos --setParameter 'healthMonitoringIntervals={ values:[ { type:"ldap", interval: "30000"} ] }'` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#health-managers)
- ```bash — `mongos --setParameter 'progressMonitor={"interval": 1000, "deadline": 300}'` … — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#progressmonitor-fields)
- ```javascript — `host : <string>,` … — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#instance-information)

## Measurements and reference values

- Queries that involve multiple shards per request are less efficient and do not scale linearly when shards are added. A Netdata guide estimates a scatter-gather query on a 50-shard cluster can use up to 50x the CPU, memory and I/O of a targeted query. The 50x figure is an unbenchmarked estimate, not a measured number. — [source](https://www.mongodb.com/docs/manual/core/sharding-choose-a-shard-key/)

## Problems, failure modes and limitations

- | Name | Type | Required | Description | | --- | --- | --- | --- | | --clusterName | string | true | Human-readable label that identifies the cluster. | | --envelope | envelope | false | Flag that indicates whether Application wraps the response in an envelope JSON object. Some API clients cannot access the HTTP response headers or status code. To remediate this, set envelope=true in the query. Endpoints that return a list of results use the results object as an envelope. Application adds the status parameter to the response body. | | --groupId | string | true | Unique 24-hexadecimal digit str — [source](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-api-queryShapeInsights-getQueryShapeDetails.md#options)
- | Name | Type | Required | Description | | --- | --- | --- | --- | | --collectionName | string | true | Human-readable label that identifies the collection. | | --databaseName | string | true | Human-readable label that identifies the database. | | --end | string | false | Date and time when MongoDB Cloud stops reporting the metrics. This parameter expresses its value in the ISO 8601 timestamp format in UTC. Include this parameter when you do not set **period**. | | --envelope | envelope | false | Flag that indicates whether Application wraps the response in an envelope JSON object. Some API c — [source](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-api-monitoringAndLogs-getIndexMeasurements.md#options)
- If you cannot stop all writes to the collection during this procedure, do not use the procedure on this page. Instead, build your unique index on the collection by issuing [`db.collection.createIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.createindex.md#mongodb-method-db.collection.createIndex) on the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) for a sharded cluster. — [source](https://www.mongodb.com/docs/manual/tutorial/build-indexes-on-sharded-clusters.md#unique-indexes)
- If a given field is an array in any document in the collection, wildcard indexes cannot support queries for documents where that field is not equal to `null`. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard/reference/restrictions.md#array-field-is-not-equal-to-null)
- For example, consider an `inventory` collection with a wildcard index on `product_attributes`. The wildcard index **cannot** support the following queries if `product_attributes.tags` is an array in any document in the collection: — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard/reference/restrictions.md#array-field-is-not-equal-to-null)
- Wildcard indexes store entries for the contents of a document or array, not the document or array itself. Therefore, wildcard indexes cannot support exact equality matches on documents or arrays. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard/reference/restrictions.md#equality-matches-on-documents-and-arrays)
- For example, consider an `inventory` collection with a wildcard index on `product_attributes`. The wildcard index cannot support the following queries: — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard/reference/restrictions.md#equality-matches-on-documents-and-arrays)
- Similarly, wildcard indexes cannot support exact **inequality** matches on documents and arrays. For example, a wildcard index on `product_attributes` cannot support the following queries: — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard/reference/restrictions.md#equality-matches-on-documents-and-arrays)
- Wildcard indexes are [sparse](https://www.mongodb.com/docs/manual/core/index-sparse.md#std-label-index-type-sparse) and do not index empty fields. Therefore, wildcard indexes cannot support queries for documents where a field does not exist. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard/reference/restrictions.md#field-does-not-exist)
- For example, consider an `inventory` collection with a wildcard index on `product_attributes`. The wildcard index cannot support all of the predicates in the following query: — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard/reference/restrictions.md#multi-field-query-predicates)
- Query settings have more functionality than index filters. Also, index filters aren't persistent and you cannot easily create index filters for all cluster nodes. To add query settings and explore examples, see [`setQuerySettings`.](https://www.mongodb.com/docs/manual/reference/command/setquerysettings.md#mongodb-dbcommand-dbcmd.setQuerySettings) — [source](https://www.mongodb.com/docs/manual/reference/command/planCacheSetFilter.md#set-filter-on-plan-cache-query-shape-consisting-of-predicate-and-collation)
- - The Performance Advisor cannot suggest indexes for MongoDB databases configured to use the [ctime timestamp format](https://www.mongodb.com/docs/manual/reference/program/mongod/#cmdoption-mongod-timestampformat). As a workaround, set the timestamp format for such databases to either [iso8601-utc](https://www.mongodb.com/docs/manual/reference/program/mongod/#cmdoption-mongod-timestampformat) or [iso8601-local.](https://www.mongodb.com/docs/manual/reference/program/mongod/#cmdoption-mongod-timestampformat) — [source](https://www.mongodb.com/docs/atlas/analyze-slow-queries.md#best-practices-for-query-performance)
- A hexadecimal string that represents the hash of the [plan cache query shape](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-plan-cache-query-shape) and is dependent only on the plan cache query shapes. `planCacheShapeHash` can help identify slow queries (including the query filter of write operations) with the same plan cache query shape. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Scatter-gather is not always bad. For aggregation queries over a large amount of data, MongoDB docs say scatter-gather lets the query run in parallel on all shards and can be useful. The warning targets frequent, latency-sensitive queries. — [source](https://www.mongodb.com/docs/manual/core/sharding-choose-a-shard-key/)
- - [profiler log messages](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md#std-label-database-profiler) and [diagnostic log messages (i.e. mongod/mongos log messages)](https://www.mongodb.com/docs/manual/reference/log-messages.md#std-label-log-messages-ref) when logging slow queries. — [source](https://www.mongodb.com/docs/manual/core/query-plans.md#availability)
- For a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance, the command only configures how operations get written to the diagnostic log. You cannot enable the [database profiler](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md#std-label-database-profiler) on a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance because `mongos` does not have any collections that the profiler can write to. — [source](https://www.mongodb.com/docs/manual/reference/command/profile.md#definition)
- | Field | Type | Description | | --- | --- | --- | | `profile` | int | Configures the profiler level. The following profiler levels are available: `0`The profiler is off and does not collect any data. This is the default profiler level.`1`The profiler collects data for operations that exceed the `slowms` threshold or match a specified [filter.](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#std-label-set-profiling-level-options-filter)When a filter is set:The `slowms` and `sampleRate` options are not used for profiling.; The profiler only captures operations that — [source](https://www.mongodb.com/docs/manual/reference/command/profile.md#command-fields)
- With [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances, the method sets the `slowms`, `sampleRate` and `filter` configuration settings, which configure how operations get written to the diagnostic log. You cannot enable the [Database Profiler](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md) on a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance because `mongos` does not have any collections that the profiler can write to. The `profile` level m — [source](https://www.mongodb.com/docs/manual/reference/method/db.setProfilingLevel.md#definition)
- Starting in MongoDB 8.3, you cannot specify `SCRAM-SHA-1` for [`authenticationMechanisms`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.authenticationMechanisms) while also specifying [`mongod --tlsFIPSMode`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--tlsFIPSMode) or [`mongos --tlsFIPSMode`.](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-option-mongos.--tlsFIPSMode) — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#authentication-parameters)
- [`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) logs a warning on connection if the presented X.509 certificate expires within `30` days of the `mongod/mongos` system clock. Use the [`tlsX509ExpirationWarningThresholdDays`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.tlsX509ExpirationWarningThresholdDays) parameter to control the certificate expiration warning threshold: — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#oidcidentityproviders-fields)
- Base delay in milliseconds for the default retry strategy used in internal server-side connections, such as [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-program-mongos) and [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-program-mongod). The server uses this value as the initial delay for exponential backoff between retries on operations that fail due to overload. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#general-parameters)
- Maximum delay in milliseconds for the default retry strategy used by internal server-side client connections, such as [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-program-mongos) and [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-program-mongod). The server uses this value as the maximum wait time between retries of operations that fail due to overload. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#general-parameters)
- This parameter controls whether overload-induced retries against other servers in the cluster avoid servers that recently returned an error labeled `SystemOverloadedError`. It affects operations that perform remote targeting, for example when `mongos` retries requests against shard members or when `mongod` performs remote reads during aggregation. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#general-parameters)
- When you set this parameter to `true`, retry logic for remote targeting prefers non-overloaded members for operations that fail with `SystemOverloadedError`. For example, when `mongos` retries reads: — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#general-parameters)
- The `tcpFastOpenQueueSize` parameter sets the size of the queue of pending TFO connections. While the queue is full, the `mongod/mongos` falls back to the normal three-way handshake for incoming client requests and ignores the presence of TFO cookies. Once the queue size falls back below the limit, the `mongod/mongos` begins accepting new TFO cookies. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#general-parameters)
- Configure 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) to redact any message accompanying a given log event before logging. This prevents the program from writing potentially sensitive data stored on the database to the diagnostic log. Metadata such as error or operation codes, line numbers, and source file names are still visible in the logs. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#logging-parameters)
- By default, a [`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) with [TLS/SSL enabled](https://www.mongodb.com/docs/manual/tutorial/configure-ssl.md#std-label-configure-mongod-mongos-for-tls-ssl) and `net.ssl.allowConnectionsWithoutCertificates` : `true` lets clients connect without providing a certificate for validation while logging an warning. Set `suppressNoTLSPeerCertificateWarning` to `1` or `true` to suppress those warnings. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#logging-parameters)
- If the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) cannot create the specified directory, the diagnostic data capture is disabled for that instance. [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) may not be able to create the specified directory if a file with the same name already exists in the path or if the process does not have permissions to create the directory. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#diagnostic-parameters)
- When set on a sharded cluster with a single shard, enables direct connection warnings. If a user connects directly to the single-shard cluster, `mongod` logs a warning every hour and updates [`shardingStatistics.unauthorizedDirectShardOps`](https://www.mongodb.com/docs/manual/reference/command/serverstatus.md#mongodb-serverstatus-serverstatus.shardingStatistics.unauthorizedDirectShardOps) with unauthorized direct shard operations. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- If [`metadataRefreshInTransactionMaxWaitBehindCritSecMS`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.metadataRefreshInTransactionMaxWaitBehindCritSecMS) is too low, [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) could use all of its retry attempts and return an error. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- If [`metadataRefreshInTransactionMaxWaitMS`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.metadataRefreshInTransactionMaxWaitMS) is too low, [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) could use all of its retry attempts and return an error. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- On a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance, this parameter sets the policy that determines the minimum size limit of its connection pools to nodes within replica sets. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- The amount of time to wait from a [Health Managers Overview](https://www.mongodb.com/docs/manual/administration/health-managers.md#std-label-health-managers-overview) failure until the [mongos](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-program-mongos) is removed from the cluster, in seconds. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#health-manager-parameters)
- When a failure is detected and a Health Manager is configured as `critical`, the server waits for the specified interval before removing the `mongos` from the cluster. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#health-manager-parameters)
- | Intensity Level | Description | | --- | --- | | `critical` | The Health Manager on this facet is enabled and has the ability to move the failing [mongos](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-program-mongos) out of the cluster if an error occurs. The Health Manager waits the amount of time specified by [`activeFaultDurationSecs`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.activeFaultDurationSecs) before stopping and moving the [mongos](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-program-mongos) out — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#intensity-levels)
- If [runtime audit configuration](https://www.mongodb.com/docs/manual/tutorial/configure-audit-filters.md#std-label-configure-audit-filters-at-runtime) is enabled, the [`auditAuthorizationSuccess`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.auditAuthorizationSuccess) parameter should not appear in the `mongod` or `mongos` configuration file. The server will fail to start if the parameter is present. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#auditing-parameters)
- - You cannot use `$listSampledQueries` directly against a [`--shardsvr`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--shardsvr) replica set. When running on a sharded cluster, `$listSampledQueries` must run against a `mongos`. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries.md#limitations)
- Calculated across all shards, the highest estimate of the number of seconds remaining. If the time estimate cannot be computed, the value is set to -1. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#shard)
- Calculated across all shards, the lowest estimate of the number of seconds remaining. If the time estimate cannot be computed, the value is set to -1. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#shard)
- On hosts with Cyrus SASL 2.1.28 or later, MongoDB does not support LDAP SASL binding with the `DIGEST-MD5` mechanism. If you set [`security.ldap.bind.method`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-security.ldap.bind.method) to `sasl` and specify `DIGEST-MD5` in [`security.ldap.bind.saslMechanisms`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-security.ldap.bind.saslMechanisms), `mongod` and `mongos` fail to start. — [source](https://www.mongodb.com/docs/manual/reference/program/mongod.md#ldap-authentication-or-authorization-options)
- In MongoDB versions earlier than 6.0, if the `findAndModify` command is run on a sharded cluster, [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) discards the [`writeConcernError`](https://www.mongodb.com/docs/manual/reference/method/bulkwriteresult.md#mongodb-data-writeConcernError) document if the shard response contains an error. In MongoDB 6.0 and later, [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) returns `writeConcernError`. — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.findAndModify.md#write-concern-errors)
- All updateOne(), replaceOne() and deleteOne() operations must include the shard key or _id in the query document. MongoDB returns an error if these methods are used without the shard key or _id. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- The mongos binary cannot connect to mongod instances whose feature compatibility version (FCV) is greater than that of the mongos. For example, you cannot connect a MongoDB 4.0 version mongos to a 4.2 sharded cluster with FCV set to 4.2. You can, however, connect a MongoDB 4.0 version mongos to a 4.2 sharded cluster with FCV set to 4.0. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- The [profiler entries](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md#std-label-database-profiler) and the [diagnostic log messages (i.e. mongod/mongos logmessages)](https://www.mongodb.com/docs/manual/reference/log-messages.md#std-label-log-message-slow-ops) for read/write operations include: — [source](https://www.mongodb.com/docs/manual/reference/log-messages.md#logging-slow-operations)
- When you run the sh.shardCollection() method, the balancer begins distributing the collection data to other shards in the cluster. A single shard can only participate in one chunk migration at a time. When MongoDB succeeds in copying a range of data from one shard to another, the range on the donor shard is marked for removal by the range deleter. This process is slow and resource intensive. — [source](https://www.mongodb.com/docs/manual/sharding/)

## Comparisons and alternatives

- Number of times a collection scan occurred during query execution. During a collection scan, each document in a collection is compared to the query predicate. Collection scans occur if no appropriate [index](https://www.mongodb.com/docs/manual/indexes.md#std-label-indexes) exists that [covers](https://www.mongodb.com/docs/manual/core/query-optimization.md#std-label-indexes-covered-queries) the query. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#execution-plan-statistics-for-query-with-lookup-pipeline-stage)
- Starting in MongoDB 9.0, you can use the `queryKnobs` setting to override internal server parameters for a single [query shape](https://www.mongodb.com/docs/manual/core/query-shapes.md#std-label-query-shapes) instead of the whole instance. Set the `queryKnobs` field for targeted queries to mitigate the impact of one regressed shape without changing behavior for other workloads on the same deployment. — [source](https://www.mongodb.com/docs/manual/reference/command/setQuerySettings.md#query-knobs)
- Starting in MongoDB 8.0, use query settings instead of adding [index filters](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-index-filters). Index filters are deprecated starting in MongoDB 8.0. — [source](https://www.mongodb.com/docs/manual/reference/command/planCacheSetFilter.md#set-filter-on-plan-cache-query-shape-consisting-of-predicate-and-collation)
- updateOne(), replaceOne() and deleteOne() must include the shard key or _id; otherwise MongoDB returns an error instead of broadcasting. updateMany() and deleteMany() are broadcast unless the query specifies the full shard key. Multi-update operations are always broadcast. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- Running `$currentOp` with [localOps:true](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentop.md#std-label-currentOp-stage-localOps) provides a composite view of the in-progress transactions run on that [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), rather than information on individual shards. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp.md#mongos-composite-view-output)
- [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) and [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) do not rely on `disableSplitHorizonIPCheck` for validation at startup. Legacy `mongod` and `mongos` instances that use IP addresses instead of host names can start after an upgrade. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#replication-and-consistency)
- | Condition | Recommended Alert Threshold: Low Priority | Recommended Alert Threshold: High Priority | Key Insights | | --- | --- | --- | --- | | Oplog Window | < 24h for 5 minutes | < 1h for 10 minutes | Monitor the replication oplog window, together with replication headroom, to determine whether the secondary may soon require a full resync. The replication oplog window often helps to determine in advance the resilience of secondaries to planned and unplanned outages. | | [Election](https://www.mongodb.com/docs/manual/core/replica-set-elections/) events | > 3 for an hour, notify after 5 minu — [source](https://www.mongodb.com/docs/atlas/architecture/current/monitoring-alerts.md#recommended-atlas-alert-configurations)
- See Targeted Operations vs. Broadcast Operations for more on targeted and broadcast operations. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- Targeted Operations vs. Broadcast Operations — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- On a sharded cluster, this is reported on `mongos` instead of `mongod`. On a replica set, this is reported on `mongod`. — [source](https://www.mongodb.com/docs/manual/reference/command/currentOp.md#output-fields)
- See [Targeted Operations vs. Broadcast Operations](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#std-label-sharding-query-isolation) for more on targeted and broadcast operations. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#routing-and-results-process)

## Facts and statements

- - Run `db.collection.createIndex()` on the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) for a sharded cluster — [source](https://www.mongodb.com/docs/manual/core/index-unique.md#building-unique-index-on-replica-sets-and-sharded-clusters)
- - `SHARD_MERGE` for merging results from shards — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#classic-execution-engine)
- - `SHARDING_FILTER` for filtering out orphan documents from shards — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#classic-execution-engine)
- The [query optimizer](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-query-optimizer) uses query settings as an additional input during query planning. Index hints in query settings restrict the set of indexes available to the planner, but don't guarantee that the planner will use the index. The planner can still select a collection scan as the winning plan for a given query shape hash. — [source](https://www.mongodb.com/docs/manual/reference/command/setQuerySettings.md#definition)
- - Atlas always creates indexes for entire clusters. If you create an index while viewing the Performance Advisor for a single shard in a sharded cluster, Atlas creates that index for the entire sharded cluster. — [source](https://www.mongodb.com/docs/atlas/performance-advisor.md#behavior-and-limitations)
- For the query optimizer to choose this partial index, the query predicate must include a condition on the `name` field as well as a *non-null* match on the `email` field. — [source](https://www.mongodb.com/docs/manual/core/index-partial.md#comparison-with-sparse-indexes)
- Connect [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) to a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance in the sharded cluster and disable migrations for the collection where you want to perform the rolling build index: — [source](https://www.mongodb.com/docs/manual/tutorial/build-indexes-on-sharded-clusters.md#a-stop-migrations)
- For the plan cache query shape, the query optimizer only uses indexed plans that use the index `{ item: 1, order_date: 1, quantity: 1 }`. — [source](https://www.mongodb.com/docs/manual/reference/command/planCacheSetFilter.md#set-filter-on-plan-cache-query-shape-consisting-of-predicate-and-collation)
- - Issue an index build [`db.collection.createIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.createindex.md#mongodb-method-db.collection.createIndex) from a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance. The operation only builds the collection's index on the shard(s) missing the index. — [source](https://www.mongodb.com/docs/manual/tutorial/manage-indexes.md#find-inconsistent-indexes-across-shards)
- The operation returns a document that details the processing of the aggregation pipeline. For example, the document may show, among other details, which index, if any, the operation used. If the `movies` collection is a sharded collection, the document also shows the division of labor between the shards and the merge operation, and for targeted queries, the targeted shards. — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate.md#return-information-on-aggregation-pipeline-operation)
- For sharded collections, explain returns the serverInfo for each accessed shard, and a top-level serverInfo object for the mongos. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- The original query shape of the mongos operation may differ after the mongos sends the operation to the mongod . — [source](https://www.mongodb.com/docs/manual/reference/log-messages/)
- The Performance Advisor also shows each executed sample query that matches the query shape, with specific metrics for that query. — [source](https://www.mongodb.com/docs/atlas/performance-advisor.md#sample-queries)
- The following example shows how MongoDB uses bounds intersection to define a smaller range of values to query, resulting in improved query performance. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-bounds-intersection)
- The following example shows how MongoDB uses compound bounds to define a more efficient query constraint, resulting in improved query performance. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-compound-bounds-of-non-array-field-and-array-field)
- The Performance Advisor monitors queries that take longer than `100` milliseconds to execute and groups these queries into common [query shapes](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-query-shape). The Performance Advisor calculates the inefficiency of each query shape by considering the following aggregated metrics from queries which match the shape: — [source](https://www.mongodb.com/docs/atlas/performance-advisor/index-ranking.md#how-performance-advisor-suggests-and-ranks-indexes)
- Wildcard indexes **can** support queries where the field equals an empty document `{}`. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard/reference/restrictions.md#equality-matches-on-documents-and-arrays)
- In the case that a single wildcard index could support multiple query fields, MongoDB can only use the wildcard index to support one of the query fields. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard/reference/restrictions.md#multi-field-query-predicates)
- Instead, MongoDB uses the wildcard index to support only one of the query predicates. MongoDB automatically chooses which predicate to support based on relevant wildcard index paths. The unsupported query predicates are shown in the [`rejectedPlans`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.queryPlanner.rejectedPlans) of the [explain results.](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-results) — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard/reference/restrictions.md#multi-field-query-predicates)
- This is also true for compound wildcard indexes. The wildcard term of a compound index can only support one query predicate, although the non-wildcard terms can support the remaining predicates. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard/reference/restrictions.md#multi-field-query-predicates)
- MongoDB may use the same wildcard index to support each independent argument of the query [`$or`](https://www.mongodb.com/docs/manual/reference/operator/query/or.md#mongodb-query-op.-or) or aggregation [`$or`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/or.md#mongodb-expression-exp.-or) operators. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard/reference/restrictions.md#multi-field-query-predicates)
- Consider the following wildcard index on the `products` collection: — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard/reference/restrictions.md#queries-with-sort)
- The following example creates an index filter for the `orders` collection. The filter applies to queries whose predicate is an equality match on the `item` field and the collation `en_US` (English United States). — [source](https://www.mongodb.com/docs/manual/reference/command/planCacheSetFilter.md#set-filter-on-plan-cache-query-shape-consisting-of-predicate-and-collation)
- Starting in MongoDB 6.0, an index filter uses the [collation](https://www.mongodb.com/docs/manual/reference/collation.md#std-label-collation) previously set using the [`planCacheSetFilter`](https://www.mongodb.com/docs/manual/reference/command/plancachesetfilter.md#mongodb-dbcommand-dbcmd.planCacheSetFilter) command. — [source](https://www.mongodb.com/docs/manual/reference/command/planCacheSetFilter.md#set-filter-on-plan-cache-query-shape-consisting-of-predicate-and-collation)
- - Create queries that your current indexes support to reduce the time needed to search for your results. — [source](https://www.mongodb.com/docs/atlas/analyze-slow-queries.md#best-practices-for-query-performance)
- - Avoid creating documents with large array fields that require a lot of processing to search and index. — [source](https://www.mongodb.com/docs/atlas/analyze-slow-queries.md#best-practices-for-query-performance)
- - Optimize your indexes and remove unused or inefficient indexes. Too many indexes can negatively impact write performance. — [source](https://www.mongodb.com/docs/atlas/analyze-slow-queries.md#best-practices-for-query-performance)
- - Consider the suggested indexes from the [Performance Advisor](https://www.mongodb.com/docs/atlas/performance-advisor.md#std-label-performance-advisor) with the highest Impact scores and lowest Average Query Targeting scores. — [source](https://www.mongodb.com/docs/atlas/analyze-slow-queries.md#best-practices-for-query-performance)
- - Perform [rolling index builds](https://www.mongodb.com/docs/manual/tutorial/build-indexes-on-replica-sets/#rolling-index-builds-on-replica-sets) to reduce the performance impact of building indexes on [replica sets](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-replica-set) and [sharded clusters.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-sharded-cluster) — [source](https://www.mongodb.com/docs/atlas/analyze-slow-queries.md#best-practices-for-query-performance)
- - [Drop unused, redundant, and hidden indexes](https://www.mongodb.com/docs/atlas/performance-advisor/drop-indexes.md#std-label-pa-drop-index) to improve write performance and free storage space. — [source](https://www.mongodb.com/docs/atlas/analyze-slow-queries.md#best-practices-for-query-performance)
- MongoDB runs the [query optimizer](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-read-operations-query-optimization) to choose the winning plan, executes the winning plan to completion, and returns statistics describing the execution of the winning plan. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#executionstats-mode)
- Time in milliseconds the query planner spent on query optimization. This result doesn't include time spent optimizing inner [`$lookup`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup.md#mongodb-pipeline-pipe.-lookup) queries. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- A document that details the plan selected by the [query optimizer.](https://www.mongodb.com/docs/manual/core/query-plans.md) — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- A document that details the plan selected by the [query optimizer](https://www.mongodb.com/docs/manual/core/query-plans.md). MongoDB presents the plan as a tree of stages. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Array of candidate plans considered and rejected by the query optimizer. The array can be empty if there were no other candidate plans. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Starting in MongoDB 8.0, `explain` outputs the following field: — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#query-shape-hash)
- If the application is instead connected to a [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod), the returned document does not include the `isdbgrid` string. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#confirm-connection-to-mongos-instances)
- For queries that don't include the shard key, [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) must query all shards, wait for their responses and then return the result to the application. These "scatter/gather" queries can be long running operations. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#targeted-operations-vs-broadcast-operations)
- [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances broadcast queries to all shards for the collection **unless** the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) can determine which shard or subset of shards stores this data. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#broadcast-operations)
- The [`updateMany()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.updatemany.md#mongodb-method-db.collection.updateMany) and [`deleteMany()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.deletemany.md#mongodb-method-db.collection.deleteMany) methods are broadcast operations, unless the query document specifies the shard key in full. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#broadcast-operations)
- The [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) program *can* route queries that include the full shard key or either of the following shard key prefixes at a specific shard or set of shards: — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#targeted-operations)
- All [`insertOne()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.insertone.md#mongodb-method-db.collection.insertOne) operations target to one shard. Each document in the [`insertMany()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.insertmany.md#mongodb-method-db.collection.insertMany) array targets to a single shard, but there is no guarantee all documents in the array insert into a single shard. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#targeted-operations)
- Depending on the distribution of data in the cluster and the selectivity of the query, [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) may still perform a [broadcast operation](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#std-label-sharding-mongos-broadcast) to fulfill these queries. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#targeted-operations)
- A query without the shard key is broadcast to all shards for the collection. mongos must query every shard, wait for all responses, then merge. MongoDB calls these scatter/gather queries and says they can be long running. Docs say to favor targeted operations over broadcast ones. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- Including the shard key does not guarantee a single-shard route. Depending on data distribution and query selectivity, mongos may still broadcast (for example a range predicate spanning chunks on several shards). — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- Zone sharding does not support time series collections. The balancer always distributes data in sharded time series collections evenly across all shards in the cluster. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-considerations.md#zone-sharding)
- The IP address (or hostname) and the ephemeral port of the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) where the operation originates. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp.md#output-fields)
- Commit coordination is handled by a shard, and `$currentOp` (run either on a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) or a shard member) returns a shard's coordination information only for transactions the shard is currently coordinating. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp.md#output-fields)
- On [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), you can set `profile` level to: — [source](https://www.mongodb.com/docs/manual/reference/command/profile.md#definition)
- Available tabs: other tabs: standalone, repl-set, mongos --> — [source](https://www.mongodb.com/docs/manual/reference/method/db.setProfilingLevel.md)
- The following example sets for a [`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: — [source](https://www.mongodb.com/docs/manual/reference/method/db.setProfilingLevel.md#disable-profiler-and-set-slow-operation-threshold-and-sample-rate)
- - the `--setParameter` command-line option for [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--setParameter) and [`mongos`:](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-option-mongos.--setParameter) — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#synopsis)
- ```bash mongod --setParameter <parameter>=<value> mongos --setParameter <parameter>=<value> ``` — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#synopsis)
- For additional configuration options, see [Self-Managed Configuration File Options](https://www.mongodb.com/docs/manual/reference/configuration-options.md#std-label-configuration-options), [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) and [`mongos`.](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#synopsis)
- Starting in MongoDB 8.3, if [`mongod --tlsFIPSMode`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--tlsFIPSMode) or [`mongos --tlsFIPSMode`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-option-mongos.--tlsFIPSMode) is enabled, `SCRAM-SHA-1` is excluded from the effective default. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#authentication-parameters)
- If not set, mongod or mongos does not attempt to bind to the LDAP server. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#authentication-parameters)
- [`saslHostName`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.saslHostName) does not affect the hostname of 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 for any purpose beyond the configuration of SASL and Kerberos. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#oidcidentityproviders-fields)
- The maximum number of seconds 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 should wait to receive the OCSP status response for its certificates. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#oidcidentityproviders-fields)
- On a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance, specifies the interval (in seconds) at which the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance checks to determine whether the in-memory cache of [user objects](https://www.mongodb.com/docs/manual/reference/system-users-collection.md) has stale data, and if so, clears the cache. If there are no changes to user objects, [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mon — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#oidcidentityproviders-fields)
- Maximum number of times the server retries an operation for internal server-side client connections, such as [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-program-mongos) and [`mongod`.](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-program-mongod) — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#general-parameters)
- Enables support for outbound TCP Fast Open (TFO) connections from the `mongod/mongos` to a client. TFO requires both the client and the `mongod/mongos` host machine support and enable TFO. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#general-parameters)
- Enables support for accepting inbound TCP Fast Open (TFO) connections to the `mongod/mongos` from a client. TFO requires both the client and `mongod/mongos` host machine support and enable TFO: — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#general-parameters)
- For [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), the diagnostic data files, by default, are stored in a directory under the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance's `--logpath` or [`systemLog.path`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-systemLog.path) directory. The diagnostic data directory is computed by truncating the logpath's file extension(s) and concatenating `diagnostic.data` to the remaining name. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#diagnostic-parameters)
- For example, if [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) has `--logpath /var/log/mongodb/mongos.log.201708015`, then the diagnostic data directory is `/var/log/mongodb/mongos.diagnostic.data/` directory. To specify a different diagnostic data directory for [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), set the [`diagnosticDataCollectionDirectoryPath`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.diagnosticDataCollectionDirectoryPath) parame — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#diagnostic-parameters)
- Specify the directory for the diagnostic directory for [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos). If the directory does not exist, [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) creates the directory. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#diagnostic-parameters)
- If unspecified, the diagnostic data directory is computed by truncating the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance's `--logpath` or [`systemLog.path`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-systemLog.path) file extension(s) and concatenating `diagnostic.data`. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#diagnostic-parameters)
- For example, if [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) has `--logpath /var/log/mongodb/mongos.log.201708015`, then the diagnostic data directory is `/var/log/mongodb/mongos.diagnostic.data/`. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#diagnostic-parameters)
- Without this setting enabled, the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) only loads a routing table as needed for incoming client connections, and only loads the specific routing table for the namespace of a given request. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- Specifies the time (in milliseconds) to wait for any ongoing database operations to complete before initiating a shutdown of [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) in response to a `SIGTERM` signal. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- Or if using the [`setParameter`](https://www.mongodb.com/docs/manual/reference/command/setparameter.md#mongodb-dbcommand-dbcmd.setParameter) command in a [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) session that is connected to a running [`mongos`:](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- Interval that a sampler (`mongos` or `mongod`) refreshes its query analyzer sample rates. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- The sample rate configured by the `configureQueryAnalyzer` command is divided among `mongos` instances in the sharded cluster or `mongod` instances in the replica set based on the traffic going through them. To make the sample rate assignment for a `mongos` or `mongod` more responsive to the traffic going through it, decrease this value. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- This example sets `queryAnalysisSamplerConfigurationRefreshSecs` to 60 seconds at startup on a `mongos` instance: — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- Maximum time that [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) goes without communication to a host before [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) drops all connections to the host. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- Maximum number of simultaneous initiating connections (including pending connections in setup/refresh state) each TaskExecutor connection pool can have to a [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) instance. You can set this parameter to control the rate at which [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) adds connections to a [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) instance. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- - On-prem deployments: `32767` for both [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) and [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) can have up to `n` TaskExecutor connection pools, where `n` is the number of cores. See [`taskExecutorPoolSize`.](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.taskExecutorPoolSize) — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- For a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) using the [`warmMinConnectionsInShardingTaskExecutorPoolOnStartup`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.warmMinConnectionsInShardingTaskExecutorPoolOnStartup) parameter, the `ShardingTaskExecutorPoolMinSize` parameter also controls how many connections to each shard host are established on startup of the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance before it begins accepting — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- Maximum time the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) waits before attempting to heartbeat an idle connection in the pool. An idle connection may be discarded during the refresh if the pool is above its [minimum size.](https://www.mongodb.com/docs/manual/reference/parameters.md#std-label-sharding-pool-minsize-parameters) — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- Maximum time the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) waits for a heartbeat before timing out the heartbeat. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- For example, if `mongos` retries an operation that was previously load shed by the shard, it uses a token in the retry. If the attempt succeeds, it returns the token to the shard plus the [`shardRetryTokenReturnRate`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.shardRetryTokenReturnRate). If the attempt fails, it tries again with a new token. If it finds the bucket empty, it doesn't retry the operation. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- The number of Task Executor connection pools to use for a given [`mongos`.](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#sharding-parameters)
- A timeout for this behavior can be configured with the [`warmMinConnectionsInShardingTaskExecutorPoolOnStartupWaitMS`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.warmMinConnectionsInShardingTaskExecutorPoolOnStartupWaitMS) parameter. If this timeout is reached, the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) will begin accepting client connections regardless of the size of its connection pool. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#error-response)
- [Progress Monitor](https://www.mongodb.com/docs/manual/administration/health-managers.md#std-label-health-managers-progress-monitor) runs tests to ensure that Health Manager checks do not become stuck or unresponsive. Progress Monitor runs these tests in intervals specified by `interval`. If a health check begins but does not complete within the timeout given by `deadline`, Progress Monitor stops the [mongos](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-program-mongos) and removes it from the cluster. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#health-managers)
- | Field | Description | Units | | --- | --- | --- | | `interval` | How often to ensure Health Managers are not stuck or unresponsive. | Milliseconds | | `deadline` | Timeout before automatically failing the [mongos](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-program-mongos) if a Health Manager check is not making progress. | Seconds | — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#progressmonitor-fields)
- Connect [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) to a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance in the sharded cluster and re-enable the migration with [`setAllowMigrations`:](https://www.mongodb.com/docs/manual/reference/command/setallowmigrations.md#mongodb-dbcommand-dbcmd.setAllowMigrations) — [source](https://www.mongodb.com/docs/manual/tutorial/build-indexes-on-sharded-clusters.md#e-enable-migrations)
- - You must run on a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos). Do not issue the operation directly on the shard. — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.findOneAndUpdate.md#shard-key-modification)
- - For a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance, see [`security.javascriptEnabled`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-security.javascriptEnabled) configuration option or the [`--noscripting`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-option-mongos.--noscripting) command-line option. — [source](https://www.mongodb.com/docs/manual/reference/operator/query/where.md#javascript-enablement)
- Available tabs: other tabs: shard, mongos, mongod --> — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md)
- The output fields vary depending on the version of MongoDB, underlying operating system platform, the storage engine, and the kind of node, including [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) or [replica set](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-replica-set) member. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#output)
- The number of incoming connections from clients to the database server. This includes connections from the current shell session and from other servers, such as [replica set](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-replica-set) members and [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances. Consider the value of [`connections.available`](https://www.mongodb.com/docs/manual/reference/command/serverstatus.md#mongodb-serverstatus-serverstatus.connections.available) for additional context. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#connections)
- *Available on both mongod and mongos.* — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#ftdccollectionmetrics)
- The number of all active local sessions cached in memory by 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 since the last refresh period. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#logicalsessionrecordcache)
- A document that reports data on MongoDB's network use. These statistics measure ingress and egress connections, specifically the traffic seen by 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) over network connections initiated by clients or other [`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-b — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#network)
- Reports data on the traffic from egress connections initiated by this `mongod` or `mongos` instance. In most cases, the egress connections are `mongos` communicating with `mongod` for sharding, or `mongod` communicating with `mongod` for replication. It is also possible that `mongod` or `mongos` are communicating with external services, such as `mongot`. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#network)
- The total number of physical bytes that `mongod` or `mongos` instances has *received* over network connections that they have initiated to other nodes/services. Physical bytes are the number of bytes that actually reside on disk. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#network)
- The total number of physical bytes that `mongod` or `mongos` instances have *sent* over network connections that they have initiated to other nodes/services. Physical bytes are the number of bytes that actually reside on disk. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#network)
- The total number of distinct requests that `mongod` or `mongos` have sent and received responses to. Use this value to provide context for the [`network.egress.bytesIn`](https://www.mongodb.com/docs/manual/reference/command/serverstatus.md#mongodb-serverstatus-serverstatus.network.egress.bytesIn) and [`network.egress.bytesOut`](https://www.mongodb.com/docs/manual/reference/command/serverstatus.md#mongodb-serverstatus-serverstatus.network.egress.bytesOut) values to ensure that MongoDB's network utilization is consistent with expectations and application use. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#network)
- The total number of physical bytes that the server has *received* over network connections initiated by clients or other `mongod` or `mongos` instances. Physical bytes are the number of bytes that actually reside on disk. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#network)
- The total number of physical bytes that the server has *sent* over network connections initiated by clients or other `mongod` or `mongos` instances. Physical bytes are the number of bytes that actually reside on disk. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#network)
- The total number of accepted incoming TCP Fast Open (TFO) connections to 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) since the `mongod` or `mongos` last started. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#network)
- Starting in MongoDB 6.2, the [`opLatencies`](https://www.mongodb.com/docs/manual/reference/command/serverstatus.md#mongodb-serverstatus-serverstatus.opLatencies) metric reports for both [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) and [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances. Latencies reported by `mongos` include operation latency time and communication time between the `mongod` and `mongos` instances. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#oplatencies)
- Starting in MongoDB 9.0, user-initiated operations that run through [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-program-mongos) only increment `external` counters. In previous releases, these operations only incremented `internal` counters. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#readpreferencecounters)
- A document that reports on the number of times [X.509](https://www.mongodb.com/docs/manual/core/security-x.509.md#std-label-security-auth-x509) has been used to authenticate against 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. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#security)
- The subject name associated with 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 TLS/SSL certificate. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#security)
- The expiration date and time of 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 TLS/SSL certificate. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#security)
- A document with data regarding the sharded cluster. The [`lastSeenConfigServerOpTime`](https://www.mongodb.com/docs/manual/reference/command/serverstatus.md#mongodb-serverstatus-serverstatus.sharding.lastSeenConfigServerOpTime) is present only for a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) or a shard member, not for a config server. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#sharding)
- The latest optime of the CSRS primary that the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-program-mongos) or the shard member has seen. The optime document includes: — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#sharding)
- On a sharded cluster with a single shard, you can control this counter by setting the `directConnectionChecksWithSingleShard` parameter to `true`. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#shard)
- | Name | Description | | --- | --- | | `allShards` | A command targeted all shards | | `manyShards` | A command targeted more than one shard | | `oneShard` | A command targeted one shard | | `unsharded` | A command was run on an unsharded collection | — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#shard)
- Running the [`serverStatus`](https://www.mongodb.com/docs/manual/reference/command/serverstatus.md#mongodb-dbcommand-dbcmd.serverStatus) command on [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) provides insight into the CRUD and aggregation operations that run on a sharded cluster. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#shard)
- Multi-shard operations can either be [scatter-gather](https://www.mongodb.com/docs/manual/core/sharding-choose-a-shard-key.md#std-label-sharding-query-patterns) or shard specific. Multi-shard scatter-gather operations can [consume more resources](https://www.mongodb.com/docs/manual/core/sharding-troubleshooting-shard-keys.md#std-label-sharding-troubleshooting-scatter-gather). By using the [`shardingStatistics.numHostsTargeted`](https://www.mongodb.com/docs/manual/reference/command/serverstatus.md#mongodb-serverstatus-serverstatus.shardingStatistics.numHostsTargeted) metrics you can tune the ag — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#shard)
- For the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), the total number of transactions aborted through this instance since its last startup. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#mongod)
- For the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), the total number of transactions committed through this instance since its last startup. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#mongod)
- For the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), the total number of transactions started on this instance since its last startup. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#mongod)
- *Available on mongos only.* — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#mongod)
- The total number of shards contacted for all transactions started through this [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) since its last startup. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#mongod)
- Total number of shards involved in the commit for all transactions started through this [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) since its last startup. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#mongod)
- | Type | Description | | --- | --- | | `noShards` | Commits of transactions that did not contact any shards. | | `singleShard` | Commits of transactions that affected a single shard. | | `singleWriteShard` | Commits of transactions that contacted multiple shards but whose write operations only affected a single shard. | | `readOnly` | Commits of transactions that only involved read operations. | | `twoPhaseCommit` | Commits of transactions that included writes to multiple shards | | `recoverWithToken` | Commits that recovered the outcome of transactions from another instance or after this inst — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#mongod)
- The cumulative number of TLS \<version> connections that have been made to 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. The value is reset upon restart. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#transportsecurity)
- MongoDB Atlas limits concurrent incoming connections based on the cluster tier and [class](https://www.mongodb.com/docs/atlas/customize-storage.md#std-label-storage-class-ui). MongoDB Atlas connection limits apply per node. For sharded clusters, MongoDB Atlas connection limits apply per [mongos](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#std-label-sharding-read-operations) router. The number of [mongos](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#std-label-sharding-read-operations) routers is equal to the number of replica set nodes ac — [source](https://www.mongodb.com/docs/manual/reference/limits.md#mongodb-atlas-connection-limits-and-cluster-tier)
- - If you only target one shard, you can use a partial shard key in the query specification or, — [source](https://www.mongodb.com/docs/manual/reference/limits.md#sharding-operational-restrictions)
- Both `mongod` and [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances default to `snappy,zstd,zlib` compressors, in that order. — [source](https://www.mongodb.com/docs/manual/reference/program/mongod.md#core-options)
- - For clients that don't provide certificates, [`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) encrypts the TLS/SSL connection, assuming the connection is successfully made. — [source](https://www.mongodb.com/docs/manual/reference/program/mongod.md#tls-options)
- During normal operation, [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) and [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances report a live account of all server activity and operations to either standard output or a log file. The following runtime settings control these options. — [source](https://www.mongodb.com/docs/manual/administration/monitoring.md#process-logging)
- You can specify these configuration operations as the command line arguments to [`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) — [source](https://www.mongodb.com/docs/manual/administration/monitoring.md#process-logging)
- - Ensure full bidirectional network connectivity between [`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), and config servers. — [source](https://www.mongodb.com/docs/manual/administration/production-checklist-operations.md#sharding)
- - Adjust the `ulimit` values on your hardware to suit your use case. If multiple [`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) instances are running under the same user, scale the `ulimit` values accordingly. See: [UNIX ulimit Settings for Self-Managed Deployments](https://www.mongodb.com/docs/manual/reference/ulimit.md) for more information. — [source](https://www.mongodb.com/docs/manual/administration/production-checklist-operations.md#linux)
- The [`db.killOp()`](https://www.mongodb.com/docs/manual/reference/method/db.killop.md#mongodb-method-db.killOp) method can be run on a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) and can kill queries (read operations) that are running on more than one shard in a cluster. — [source](https://www.mongodb.com/docs/manual/reference/method/db.killOp.md#kill-read-operations)
- 1. On the **same** [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) where the client issued the query, find the opid of the query operation to kill by running the aggregation pipeline [`$currentOp`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentop.md#mongodb-pipeline-pipe.-currentOp) with the `localOps: true`: — [source](https://www.mongodb.com/docs/manual/reference/method/db.killOp.md#from-the-mongos-instance)
- You must issue this aggregation operation on the **same** [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) where the client issued the query. — [source](https://www.mongodb.com/docs/manual/reference/method/db.killOp.md#from-the-mongos-instance)
- 2. Once you find the query operation to kill, issue [`db.killOp()`](https://www.mongodb.com/docs/manual/reference/method/db.killop.md#mongodb-method-db.killOp) with the opid on the [`mongos`:](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) — [source](https://www.mongodb.com/docs/manual/reference/method/db.killOp.md#from-the-mongos-instance)
- If the write operation is associated with a session, you can use the [`killSessions`](https://www.mongodb.com/docs/manual/reference/command/killsessions.md#mongodb-dbcommand-dbcmd.killSessions) command on the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) to kill the write operation across shards. — [source](https://www.mongodb.com/docs/manual/reference/method/db.killOp.md#kill-write-operations)
- 1. Run the aggregation pipeline [`$currentOp`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentop.md#mongodb-pipeline-pipe.-currentOp) on the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) to find the `lsid` (logical session id). — [source](https://www.mongodb.com/docs/manual/reference/method/db.killOp.md#kill-write-operations)
- 1. Using the returned `lsid` information, issue the [`killSessions`](https://www.mongodb.com/docs/manual/reference/command/killsessions.md#mongodb-dbcommand-dbcmd.killSessions) command on the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) to kill the operation on the shards. — [source](https://www.mongodb.com/docs/manual/reference/method/db.killOp.md#kill-write-operations)
- 1. From a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), run the aggregation pipeline [`$currentOp`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentop.md#mongodb-pipeline-pipe.-currentOp) to find the opid(s) of the query operation on the shards: — [source](https://www.mongodb.com/docs/manual/reference/method/db.killOp.md#kill-write-operations)
- 2. Using the opid information, issue [`db.killOp()`](https://www.mongodb.com/docs/manual/reference/method/db.killop.md#mongodb-method-db.killOp) on the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) to kill the operation on the shards. — [source](https://www.mongodb.com/docs/manual/reference/method/db.killOp.md#kill-write-operations)
- Lists the sessions cached in memory by 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. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions.md#definition)
- From the connected [`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 in-memory cache of sessions, the following aggregation operation lists all sessions: — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions.md#list-all-local-sessions)
- From 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's in-memory cache, the following aggregation operation lists all the sessions for the specified user `myAppReader@test`: — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions.md#list-all-local-sessions-for-the-specified-users)
- From the connected [`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 in-memory cache, the following aggregation operation lists all sessions for the current user **if** run with access control: — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions.md#list-all-local-sessions-for-the-current-user)
- In earlier versions, MongoDB does not allow JavaScript execution on [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator.md#javascript-enabled)
- - Use [targeted operations](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#std-label-sharding-mongos-targeted) for workloads that need to scale with the number of shards. — [source](https://www.mongodb.com/docs/manual/administration/production-checklist-development.md#sharding)
- mongod / mongos instances output all log messages in structured JSON format. Log entries are written as a series of key-value pairs, where each key indicates a log message field type, such as "severity", and each corresponding value records the associated logging information for that field type, such as "informational". Previously, log entries were output as plaintext. — [source](https://www.mongodb.com/docs/manual/reference/log-messages/)
- the --logpath option for mongos for file — [source](https://www.mongodb.com/docs/manual/reference/log-messages/)
- the --syslog option for mongos for syslog — [source](https://www.mongodb.com/docs/manual/reference/log-messages/)
- You would set these values in the configuration file or on the command line for your mongod or mongos instance. — [source](https://www.mongodb.com/docs/manual/reference/log-messages/)
- On the shard or mongos that merges the results. — [source](https://www.mongodb.com/docs/manual/reference/log-messages/)
- A mongod or mongos running with redactClientLogData redacts any message accompanying a given log event before logging, leaving only metadata, source files, or line numbers related to the event. redactClientLogData prevents potentially sensitive information from entering the system log at the cost of diagnostic detail. — [source](https://www.mongodb.com/docs/manual/reference/log-messages/)
- Cache refresh log fields are specific to sharded clusters and only appear in logs generated by the mongos router. They are not available in unsharded replica sets or standalone deployments. — [source](https://www.mongodb.com/docs/manual/reference/log-messages/)
- MongoDB mongos instances route queries and write operations to shards in a sharded cluster. mongos provides the only interface to a sharded cluster from the perspective of applications. Applications never connect or communicate directly with the shards. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- The mongos tracks what data is on which shard by caching the metadata from the config servers. The mongos uses the metadata to route operations from applications and clients to the mongod instances. A mongos has no persistent state and consumes minimal system resources. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- The most common practice is to run mongos instances on the same systems as your application servers, but you can maintain mongos instances on the shards or on other dedicated resources. See also Number of mongos and Distribution. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- The mongos then merges the data from each of the targeted shards and returns the result document. Certain query modifiers, such as sorting, are performed on each shard before mongos retrieves the results. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- Aggregation operations running on multiple shards may route results back to the mongos to merge results if they don't need to run on the database's primary shard. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- There are two cases in which a pipeline is ineligible to run on mongos. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- Generally, the fastest queries in a sharded environment are those that mongos route to a single shard, using the shard key and the cluster meta data from the config server. These targeted operations use the shard key value to locate the shard or subset of shards that satisfy the query document. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- mongos instances broadcast queries to all shards for the collection unless the mongos can determine which shard or subset of shards stores this data. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- Multi-update operations are always broadcast operations. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- The updateMany() and deleteMany() methods are broadcast operations, unless the query document specifies the shard key in full. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- mongos can route queries that include the shard key or the prefix of a compound shard key a specific shard or set of shards. mongos uses the shard key value to locate the chunk whose range includes the shard key value and directs the query at the shard containing that chunk. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- Depending on the distribution of data in the cluster and the selectivity of the query, mongos may still perform a broadcast operation to fulfill these queries. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- Starting in MongoDB 4.2, MongoDB adds the parameter ShardingTaskExecutorPoolReplicaSetMatching. This parameter determines the minimum size of the mongod / mongos instance's connection pool to each member of the sharded cluster. This value can vary during runtime. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- mongod and mongos maintain connection pools to each replica set secondary for every replica set in the sharded cluster. By default, these pools have a number of connections that is at least the number of connections to the primary. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- This aggregation stage is only available on [`mongos`.](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-program-mongos) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution.md#definition)
- Starting in MongoDB 8.0.10, you can reshard a time series collection. All shards in the time series collection must run version 8.0.10 or later to reshard. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-limitations.md#resharding)
- You would set these values in the [configuration file](https://www.mongodb.com/docs/manual/reference/configuration-options.md#std-label-configuration-options) or on the command line for your [`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. — [source](https://www.mongodb.com/docs/manual/reference/log-messages.md#systemlog-verbosity-settings)
- - On the [shard](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-shard) or [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) that merges the results. — [source](https://www.mongodb.com/docs/manual/reference/log-messages.md#time-waiting-for-shards-logged-in-remoteopwaitmillis-field)
- Calculated across all shards, the lowest estimate of the number of seconds remaining. — [source](https://www.mongodb.com/docs/manual/reference/command/currentOp.md#output-fields)
- Calculated across all shards, the highest estimate of the number of seconds remaining. — [source](https://www.mongodb.com/docs/manual/reference/command/currentOp.md#output-fields)
- Starting in MongoDB 5.0, [`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), and the legacy [`mongo`](https://www.mongodb.com/docs/manual/reference/mongo.md#mongodb-binary-bin.mongo) shell no longer support `x86_64` platforms which do not meet this minimum microarchitecture requirement. — [source](https://www.mongodb.com/docs/manual/administration/production-notes.md#x86-64)
- Starting in MongoDB 5.0, [`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), and the legacy [`mongo`](https://www.mongodb.com/docs/manual/reference/mongo.md#mongodb-binary-bin.mongo) shell no longer support `arm64` platforms which do not meet this minimum microarchitecture requirement. — [source](https://www.mongodb.com/docs/manual/administration/production-notes.md#arm64)
- The [`connPoolStats`](https://www.mongodb.com/docs/manual/reference/command/connpoolstats.md#mongodb-dbcommand-dbcmd.connPoolStats) command returns information regarding the number of open connections to the current database for [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) and [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) instances in sharded clusters. — [source](https://www.mongodb.com/docs/manual/administration/production-notes.md#manage-connection-pool-sizes)
- You need to restart [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) and [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) processes for new system-wide keepalive settings to take effect. — [source](https://www.mongodb.com/docs/manual/administration/production-notes.md#adjust-tcp-keepalive-time)
- Keepalive values greater than `300` seconds, (5 minutes) will be overridden on [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) and [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) sockets and set to `300` seconds. — [source](https://www.mongodb.com/docs/manual/administration/production-notes.md#adjust-tcp-keepalive-time)
- Windows users should consider the [Windows Server Technet Article on KeepAliveTime](https://technet.microsoft.com/en-us/library/cc957549.aspx) for more information on setting keepalive for MongoDB deployments on Windows systems. Keepalive values greater than or equal to *600000* milliseconds (10 minutes) will be ignored by [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) and [`mongos`.](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) — [source](https://www.mongodb.com/docs/manual/administration/production-notes.md#adjust-tcp-keepalive-time)
- At a minimum, ensure that each [`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 has access to two real cores or one multi-core physical CPU. — [source](https://www.mongodb.com/docs/manual/administration/production-notes.md#allocate-sufficient-ram-and-cpu)
- On Linux, you must disable *zone reclaim* and also ensure that your [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) and [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances are started by `numactl`, which is generally configured through your platform's init system. You must perform both of these operations to properly disable NUMA for use with MongoDB. — [source](https://www.mongodb.com/docs/manual/administration/production-notes.md#configuring-numa-on-linux)
- 2. Ensure that [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) and [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) are started by `numactl`. This is generally configured through your platform's init system. Run the following command to determine which init system is in use on your platform: — [source](https://www.mongodb.com/docs/manual/administration/production-notes.md#configuring-numa-on-linux)
- You must use `numactl` to start each of your [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) instances, including all [config servers](https://www.mongodb.com/docs/manual/core/sharded-cluster-config-servers.md#std-label-sharding-config-server), [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances, and clients. Edit the default **systemd** service file for each as follows: — [source](https://www.mongodb.com/docs/manual/administration/production-notes.md#configuring-numa-on-linux)
- 5. If applicable, repeat these steps for any [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances. — [source](https://www.mongodb.com/docs/manual/administration/production-notes.md#configuring-numa-on-linux)
- For information on how to list sharding operations that are active on a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), see the `localOps` parameter in [`$currentOp`.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentop.md#mongodb-pipeline-pipe.-currentOp) — [source](https://www.mongodb.com/docs/manual/reference/command/killOp.md#sharded-cluster)
- Routing with mongos: The mongos acts as a query router, providing an interface between client applications and the sharded cluster. — [source](https://www.mongodb.com/docs/manual/sharding/)
- If queries do not include the shard key or the prefix of a compound shard key, mongos performs a broadcast operation, querying all shards in the sharded cluster. These scatter/gather queries can be long running operations. — [source](https://www.mongodb.com/docs/manual/sharding/)
- You must connect to a mongos router to interact with any collection in the sharded cluster. This includes sharded and unsharded collections. Clients should never connect to a single shard to perform read or write operations. — [source](https://www.mongodb.com/docs/manual/sharding/)
- Starting in MongoDB 8.3, you can only run DDL operations and applyOps on a mongos for all sharded clusters. For Atlas clusters, these operations may be temporarily unavailable while transitioning from a replica set to a sharded cluster. — [source](https://www.mongodb.com/docs/manual/sharding/)
- You can connect to a mongos the same way you connect to a mongod using the mongosh or a MongoDB driver. — [source](https://www.mongodb.com/docs/manual/sharding/)
- serverInfo: { // serverInfo for mongos — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- - For a sharded cluster, you must issue [`db.collection.watch()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.watch.md#mongodb-method-db.collection.watch) on a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance. — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.watch.md#deployment)
- A [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance routes a query to a [cluster](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-sharded-cluster) by: — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#routing-and-results-process)
- [Aggregation operations](https://www.mongodb.com/docs/manual/core/aggregation-pipeline.md#std-label-aggregation-pipeline) running on multiple shards may route results back to the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) to merge results if they don't need to run on the database's [primary shard.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-primary-shard) — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#routing-and-results-process)
- There are two cases in which a pipeline is ineligible to run on [`mongos`.](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#routing-and-results-process)
- Connect [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) to the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) for your sharded cluster. Specify the `host` and `port` on which the `mongos` is running: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-shard-collection.md#create-a-sharded-time-series-collection)

## Related concepts

- sharded query targeting — is a part of MongoDB sharded query targeting and scatter-gather
- index — is a related of MongoDB sharded query targeting and scatter-gather
- query shape — is a related of MongoDB sharded query targeting and scatter-gather
- query optimization — is a hypernym of MongoDB sharded query targeting and scatter-gather
