Skip to content

Commit

Permalink
Merge pull request #14208 from Automattic/vkarpov15/gh-14207
Browse files Browse the repository at this point in the history
docs: update findOneAndUpdate tutorial to use includeResultMetadata
  • Loading branch information
vkarpov15 committed Jan 2, 2024
2 parents 5b4a9c2 + c561c93 commit 037a823
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
8 changes: 4 additions & 4 deletions docs/tutorials/findoneandupdate.md
Expand Up @@ -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

Expand Down Expand Up @@ -51,17 +51,17 @@ Using the `upsert` option, you can use `findOneAndUpdate()` as a find-and-[upser
[require:Tutorial.*findOneAndUpdate.*upsert]
```

<h2 id="raw-result">The `rawResult` Option</h2>
<h2 id="includeresultmetadata">The <code>includeResultMetadata</code> Option<h2 id="rawresult"></h2></h2>

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:
Expand Down
1 change: 0 additions & 1 deletion test/model.findOneAndUpdate.test.js
Expand Up @@ -1334,7 +1334,6 @@ describe('model: findOneAndUpdate:', function() {
const opts = {
new: true,
upsert: false,
passRawResult: false,
overwrite: false,
runValidators: true
};
Expand Down

0 comments on commit 037a823

Please sign in to comment.