Array.splice works, Lodash.remove doesn't Array.splice works, Lodash.remove doesn't mongoose mongoose

Array.splice works, Lodash.remove doesn't


In short, Mongoose and Lodash do not appear to be compatible (at least for this use case).


Mongoose wraps Array.splice with its own method.

Please see line 568 of Mongoose source

However, Lodash explicitly calls the default Array.splice, which circumvents the wrapped version.

Please see (in order) lines 7847, 7864, 3857, 3866, 1484, 1435 of Lodash source


According to the docs remove "Returns the new array of removed elements". So in order to achieve what you want you need to assign the return value of the invokation to user.items.

https://lodash.com/docs/4.17.10#remove