Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update findOneAndUpdate tutorial to use includeResultMetadata #14208

Merged
merged 2 commits into from Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 `includeResultMetadata` Option<h2 id="rawresult"></h2></h2>
vkarpov15 marked this conversation as resolved.
Show resolved Hide resolved

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