lowdb icon indicating copy to clipboard operation
lowdb copied to clipboard

How to remove all items in an array

Open gnusiva opened this issue 5 years ago • 1 comments

hi all,

I have this use to remove all items from an array.

Later I found that it is available in lodash library.

you can remove all items from an array by

db.get('users').find({username: token.username}).get('recentMovies').remove( (item) => true).write();

'recentMovies' is an array in my case.

Note: I am returning true always for all the items, you can programmatically do that also. .remove( (item) => true)

gnusiva avatar Jan 18 '21 01:01 gnusiva

Can you not just use set?

db.get('users').find({username: token.username}).set('recentMovies', []).write();

james2doyle avatar May 20 '21 17:05 james2doyle