.subtract()

Subtracts the provided value from the value of the provided key. If no existing number, the provided value will be subtracted from 0 (zero).

subtract(key, value)

Parameter

Description

key

String

The key that will have its value decremented

value

Number

The value to decrement

Returns

Description

The updated data from the provided key's root

db.get('balance'); // 350

db.subtract('balance', 100); // 250

Also allows the use of dot notation:

db.get('account'); // { owner: '5antos', balance: 800 }

db.subtract('account.balance', 200); // { owner: '5antos', balance: 600 }

Last updated