.update()
Updates the provided key's value with the provided callback.
update(key, updateCallback)
Returns
Description
The updated data from the provided key's root
db.set('user', { name: 'Peter' }); // { name: 'Peter' }
db.update('user', (d) => d.name += "👨🏻💻"); // { name: 'Peter👨🏻💻' }
Also allows the use of dot notation:
db.get('user'); // { name: '5antos' }
db.update('user.name', (d) => d = d.toUpperCase()); // { name: '5ANTOS' }
And even a way to delete a key from the data:
db.get('person'); // { name: 'Peter', age: 19 }
db.update('person', (d) => delete d.age); // { name: 'Peter' }
db.get('user'); // { name: '5ANTOS' }
db.update('user.name', (d) => d = d.toLowerCase()); // { name: '5antos' }
// is the same as
db.update('user.name', (d) => d.toLowerCase()); // { name: '5antos' }
Last updated
Was this helpful?