Overview
When you use the Node.js driver to perform a server operation, you can limit the duration allowed for each stage of the operation. Specify the per-stage timeout options to limit stages such as server selection, connection checkout, and server-side execution. When a timeout expires, the Node.js driver raises a timeout exception.
Warning
The timeoutMS and timeoutMode connection options are deprecated in Node.js driver v7.8 and later. These options have no effect and are slated for removal in a future release.
In Node.js driver versions 6.11 through 6.21 and 7.0 through 7.7, the timeoutMS connection option can cause connection pool desynchronization. The desynchronization occurs after an operation timeout and can expose other users' data. To learn more, see the upgrade warning in the Version 7.8 release notes.
Use the per-stage timeout options described on this page instead.
Per-Stage Timeout Options
The Node.js driver provides the following options to limit the time allowed for each stage of a server operation:
serverSelectionTimeoutMS: Limits the time in milliseconds that the driver blocks for server selection before raising an error.waitQueueTimeoutMS: Limits the time in milliseconds that the driver spends attempting to check out a connection from a server's connection pool.socketTimeoutMS: Limits the time in milliseconds that the driver spends attempting to send or receive on a socket.maxTimeMS: Limits the time in milliseconds that the server spends executing an operation after the operation reaches the server. You can passmaxTimeMSonly to an individual operation or to a cursor.
To learn how to specify these options, including code examples, see the Connection Timeout Options section of the Specify Connection Options guide.