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

# Query Timeouts

You can specify a timeout for read operations to complete. If a query exceeds the specified time limit, MongoDB stops the query and the query does not return any results.

To prevent ongoing queries from negatively impacting deployment performance for long periods of time, specify a suitable query timeout for your application.

For details on how MongoDB stops queries that exceed a specified timeout, see [cursor.maxTimeMS Behaviors.](https://www.mongodb.com/docs/manual/reference/method/cursor.maxtimems.md#std-label-cursor-maxtimems-behaviors)

## Specify a Time Limit for Queries

To specify a time limit for a query, perform one of these actions:

- Specify the [`maxTimeMS()`](https://www.mongodb.com/docs/manual/reference/method/cursor.maxtimems.md#mongodb-method-cursor.maxTimeMS) option for a query. The `maxTimeMS` option lets you specify a query timeout at the operation level, meaning you can specify different time limits for different queries.

- Specify a global default time limit for all queries. The [`defaultMaxTimeMS`](https://www.mongodb.com/docs/manual/reference/cluster-parameters/defaultmaxtimems.md#mongodb-parameter-param.defaultMaxTimeMS) cluster parameter specifies a default time limit for individual read operations to complete, and applies to all queries that do not include the [`maxTimeMS()`](https://www.mongodb.com/docs/manual/reference/method/cursor.maxtimems.md#mongodb-method-cursor.maxTimeMS) option. If a query specifies a `maxTimeMS()` option, that value overrides the `defaultMaxTimeMS` value.

## Learn More

- [Perform Long-Running Snapshot Queries](https://www.mongodb.com/docs/manual/tutorial/long-running-queries.md#std-label-tutorial-long-running-queries)

- [Analyze Query Performance](https://www.mongodb.com/docs/manual/tutorial/evaluate-operation-performance.md#std-label-server-diagnose-queries)

- [cursor.noCursorTimeout() (mongosh method)](https://www.mongodb.com/docs/manual/reference/method/cursor.nocursortimeout.md#std-label-cursor-noCursorTimeout)
