Query.prototype.wtimeout()

Parameters
  • ms «number» number of milliseconds to wait
Returns:
  • «Query» this

If w > 1, the maximum amount of time to wait for this write to propagate through the replica set before this operation fails. The default is 0, which means no timeout.

This option is only valid for operations that write to the database

  • deleteOne()
  • deleteMany()
  • findOneAndDelete()
  • findOneAndReplace()
  • findOneAndUpdate()
  • remove()
  • update()
  • updateOne()
  • updateMany()

Defaults to the schema’s writeConcern.wtimeout option

Example:

  1. // The `deleteOne()` promise won't resolve until this `deleteOne()` has
  2. // propagated to at least `w = 2` members of the replica set. If it takes
  3. // longer than 1 second, this `deleteOne()` will fail.
  4. await mongoose.model('Person').
  5. deleteOne({ name: 'Ned Stark' }).
  6. w(2).
  7. wtimeout(1000);