typicode / lowdb

Simple and fast JSON database
MIT License
21.35k stars 918 forks source link

How can I delete and update a record/object from db.json? #526

Closed gabobaxx closed 2 years ago

typicode commented 2 years ago

Hi,

Just like you would with any JavaScript array. There's no specific API for deleting/updating, it's pure JS.

For example:

// considering db.data.posts is an array of objects
db.data.posts.shift()
console.log(db.data)
db.data.posts = db.data.posts.filter()
console.log(db.data)
db.data.posts[0].title = 'updated title'
console.log(db.data)
// etc...
db.write()