> For the complete documentation index, see [llms.txt](https://lenn.gitbook.io/db-local/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lenn.gitbook.io/db-local/methods/update.md).

# .update()

Update a document

| Parameter | Description                                                                                                                                             |                                                                                                                                                                     |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \_id      | <p>​<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>                                        | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number​</a></p><p>The id of the document that will be updated</p> |
| values    | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></p><p>Values ​​that will be updated</p> |                                                                                                                                                                     |

## ​update({ \_id }, values) <a href="#undefined" id="undefined"></a>

```javascript
User.update({ _id: 1 }, { username: "len" }).save()
// {
//   _id: 1, 
//   username: "len"
// }
```

Or update a user from find:\
\
Using [find()](https://db-local.gitbook.io/docs/methods/find) and [update()](https://db-local.gitbook.io/docs/methods/update)

```javascript
const userFound = User.find({ _id: 1 })

userFound.update({ username: "len" }).save()
// {
//   _id: 1, 
//   username: "len"
// }
```

Using only [find()](https://db-local.gitbook.io/docs/methods/find) and updating the **data** directly

```javascript
const userFound = User.find({ _id: 1 })

userFound.username = "len"
userFound.save()

// {
//   _id: 1, 
//   username: "len"
// }
```
