.set()

Sets a new value to the value of the provided key.

set(key, value, encrypt)

Parameter

Default

Description

key

String

The target key

value

JSONData

The value to set

encrypt

false

Boolean (optional)

Whether or not to encrypt the value before setting it

Returns

Description

The updated data from the provided key's root

db.set('user', { name: 'Peter' }); // { name: 'Peter' }

db.get('user'); // { name: 'Peter' }

Also allows the use of dot notation:

db.get('user'); // { name: 'Peter' }

db.set('user.age', 19); // { name: 'Peter', age: 19 }

And the possibility to encrypt the data to safely store it:

db.set('PASSWORD', 'password123', true); // d95e3df34d0a39c3177adf393e90c533:d861d25474fb4fe0c921be 

And even a way to delete an entry from the database (version 2.0.2 and above):

db.get('user'); // { name: 'Peter', age: 19 }

db.set('user.age', undefined); // { name: 'Peter' } 

Last updated