Skip to content

Commit

Permalink
docs(documents): add overwriting section
Browse files Browse the repository at this point in the history
Fix #8178
  • Loading branch information
vkarpov15 committed Sep 29, 2019
1 parent 98b5a73 commit 7fee719
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/documents.pug
Expand Up @@ -142,6 +142,28 @@ block content

Read the [validation](./validation.html) guide for more details.

### Overwriting

There are 2 different ways to overwrite a document (replacing all keys in the
document). One way is to use the
[`Document#overwrite()` function](/docs/api/document.html#document_Document-overwrite)
followed by `save()`.

```javascript
const doc = await Person.findOne({ _id });

// Sets `name` and unsets all other properties
doc.overwrite({ name: 'Jean-Luc Picard' });
await doc.save();
```

The other way is to use [`Model.replaceOne()`](/docs/api/model.html#model_Model.replaceOne).

```javascript
// Sets `name` and unsets all other properties
await Person.replaceOne({ _id }, { name: 'Jean-Luc Picard' });
```

### Next Up

Now that we've covered Documents, let's take a look at
Expand Down

0 comments on commit 7fee719

Please sign in to comment.