db-local
  • Introduction
  • Getting Started
  • Schema
  • Methods
    • .find()
      • References
      • Filters
    • .create()
    • .update()
    • .remove()
Powered by GitBook
On this page

Was this helpful?

  1. Methods

.update()

Update a document

Parameter

Description

_id

The id of the document that will be updated

values

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() and update()

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

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

Using only find() and updating the data directly

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

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

// {
//   _id: 1, 
//   username: "len"
// }
Previous.create()Next.remove()

Last updated 3 years ago

Was this helpful?

​ |

String
Number​
Object