.update()

Update a document

Parameter

Description

_id

Stringarrow-up-right | Number​arrow-up-right

The id of the document that will be updated

values

Objectarrow-up-right

Values ​​that will be updated

​update({ _id }, values)

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

Or update a user from find: Using find()arrow-up-right and update()arrow-up-right

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

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

Using only find()arrow-up-right and updating the data directly

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

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

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

Last updated