Query.prototype.w()

Parameters
  • val «String|number» 0 for fire-and-forget, 1 for acknowledged by one server, ‘majority’ for majority of the replica set, or any of the more advanced options.
Returns:
  • «Query» this

Sets the specified number of mongod servers, or tag set of mongod servers, that must acknowledge this write before this write is considered successful.

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.w option

Example:

  1. // The 'majority' option means the `deleteOne()` promise won't resolve
  2. // until the `deleteOne()` has propagated to the majority of the replica set
  3. await mongoose.model('Person').
  4. deleteOne({ name: 'Ned Stark' }).
  5. w('majority');