From 7dbe0b451cd856c5981b5f23e2fef32e2db246e7 Mon Sep 17 00:00:00 2001 From: Hafez Date: Wed, 19 Jan 2022 06:31:23 +0200 Subject: [PATCH] docs(migration): add note to change default functions to for scehma re #11233 --- docs/migrating_to_6.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/migrating_to_6.md b/docs/migrating_to_6.md index 48d46d03e30..e8651cf7ccf 100644 --- a/docs/migrating_to_6.md +++ b/docs/migrating_to_6.md @@ -221,7 +221,9 @@ const res = await Test.findOneAndUpdate({}, { $set: { name: undefined } }, { new

Document Parameter to Default Functions

-Mongoose now passes the document as the first parameter to `default` functions, which is helpful for using [arrow functions](https://masteringjs.io/tutorials/fundamentals/arrow) with defaults. This may affect you if you pass a function that expects different parameters to `default`, like `default: mongoose.Types.ObjectId`. See [gh-9633](https://github.com/Automattic/mongoose/issues/9633) +Mongoose now passes the document as the first parameter to `default` functions, which is helpful for using [arrow functions](https://masteringjs.io/tutorials/fundamentals/arrow) with defaults. + +This may affect you if you pass a function that expects different parameters to `default`, like `default: mongoose.Types.ObjectId`. See [gh-9633](https://github.com/Automattic/mongoose/issues/9633). If you're passing a default function that does **not** utilize the document, change `default: myFunction` to `default: () => myFunction()` to avoid accidentally passing parameters that potentially change the behavior. ```javascript const schema = new Schema({