From 5f7da85e4db63691d7e8e171b79097a55d71f0e5 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Sat, 30 Dec 2023 12:27:32 -0500 Subject: [PATCH 1/2] docs: update findOneAndUpdate tutorial to use includeResultMetadata --- docs/tutorials/findoneandupdate.md | 8 ++++---- test/model.findOneAndUpdate.test.js | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/tutorials/findoneandupdate.md b/docs/tutorials/findoneandupdate.md index c589b15b952..5af1b9e368c 100644 --- a/docs/tutorials/findoneandupdate.md +++ b/docs/tutorials/findoneandupdate.md @@ -6,7 +6,7 @@ However, there are some cases where you need to use [`findOneAndUpdate()`](https * [Getting Started](#getting-started) * [Atomic Updates](#atomic-updates) * [Upsert](#upsert) -* [The `rawResult` Option](#raw-result) +* [The `includeResultMetadata` Option](#includeresultmetadata) ## Getting Started @@ -51,17 +51,17 @@ Using the `upsert` option, you can use `findOneAndUpdate()` as a find-and-[upser [require:Tutorial.*findOneAndUpdate.*upsert] ``` -

The `rawResult` Option

+

The `includeResultMetadata` Option

Mongoose transforms the result of `findOneAndUpdate()` by default: it returns the updated document. That makes it difficult to check whether a document was upserted or not. In order to get the updated document and check whether MongoDB upserted a new document in the same operation, -you can set the `rawResult` flag to make Mongoose return the raw result +you can set the `includeResultMetadata` flag to make Mongoose return the raw result from MongoDB. ```acquit -[require:Tutorial.*findOneAndUpdate.*rawResult$] +[require:Tutorial.*findOneAndUpdate.*includeResultMetadata$] ``` Here's what the `res` object from the above example looks like: diff --git a/test/model.findOneAndUpdate.test.js b/test/model.findOneAndUpdate.test.js index 56ac556eb6c..55a1f48ac8a 100644 --- a/test/model.findOneAndUpdate.test.js +++ b/test/model.findOneAndUpdate.test.js @@ -1334,7 +1334,6 @@ describe('model: findOneAndUpdate:', function() { const opts = { new: true, upsert: false, - passRawResult: false, overwrite: false, runValidators: true }; From c561c9385d5042f83ce85654f9393e93d332458d Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Tue, 2 Jan 2024 10:46:26 -0500 Subject: [PATCH 2/2] Update docs/tutorials/findoneandupdate.md Co-authored-by: hasezoey --- docs/tutorials/findoneandupdate.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorials/findoneandupdate.md b/docs/tutorials/findoneandupdate.md index 5af1b9e368c..80f99fff4da 100644 --- a/docs/tutorials/findoneandupdate.md +++ b/docs/tutorials/findoneandupdate.md @@ -51,7 +51,7 @@ Using the `upsert` option, you can use `findOneAndUpdate()` as a find-and-[upser [require:Tutorial.*findOneAndUpdate.*upsert] ``` -

The `includeResultMetadata` Option

+

The includeResultMetadata Option

Mongoose transforms the result of `findOneAndUpdate()` by default: it returns the updated document. That makes it difficult to check whether