Mongoose deleteMany with "like" operator

Viewed 17

I need to delete all MongodDB documents from a collection that contains a specific string in a field. (I'm using mongoose)

The SQL query would be like

DELETE FROM users WHERE name LIKE '%test%'
1 Answers

You can do it with with $regex operator:

collection.deleteMany({ field: { $regex: 'your_string' } });
Related