Query.prototype.set()

Parameters
  • path «String|Object» path or object of key/value pairs to set

  • [val] «Any» the value to set

Returns:
  • «Query» this

Adds a $set to this query’s update without changing the operation. This is useful for query middleware so you can add an update regardless of whether you use updateOne(), updateMany(), findOneAndUpdate(), etc.

Example:

  1. // Updates `{ $set: { updatedAt: new Date() } }`
  2. new Query().updateOne({}, {}).set('updatedAt', new Date());
  3. new Query().updateMany({}, {}).set({ updatedAt: new Date() });