.pull()

Removes all elements with the same value as the provided value from an array based on the provided key.

pull(key, value)

Parameter

Description

key

Stringarrow-up-right

The key of the target array

value

JSONDataarrow-up-right

The value to remove from the array

Returns

Description

The updated data from the provided key's root

db.get('numbers'); // [1, 2, 3, 2, 4, 3, 1, 1]

db.pull('numbers', 1); // [2, 3, 2, 4, 3]

Also allows the use of dot notation:

db.get('user'); // { id: 32171, items: ['sword', 'axe'] }

db.pull('user.items', 'bow'); // { id: 32171, items: ['sword', 'axe'] }
db.pull('user.items', 'sword'); // { id: 32171, items: ['axe'] }

Last updated