1

Currently, I can add new: true flag in options in each and every findOneAndUpdate query to get updated document, but would like to know if there is an option to overwrite this on global level, so I dont need to add this flag in every findOneAndUpdate query.

Thanks in advance.

Saravanan S
  • 1,021
  • 1
  • 10
  • 24

1 Answers1

1

You can use mongoose.set()

mongoose.set('returnOriginal',false);

From the docs : This is equivalent to setting the new option to true for findOneAndX() calls by default. For schema : schema.set('returnOriginal',false). Docs link

Tushar Shahi
  • 16,452
  • 1
  • 18
  • 39