Back
I've tried
db.users.remove(*)
Although it returns an error so how do I go about clearing all records?
If you want to delete all records of a collection in MongoDB shell is by using the following method where the argument to remove() is a filter document, so passing in an empty document means 'remove all':
db.user.remove({})
If you want to eliminate everything you might be better off dropping the collection and it depends on whether you have user-defined indexes on the collection that means whether the cost of preparing the collection after dropping it exceeds the longer duration of the remove() call vs the drop() call.
31k questions
32.8k answers
501 comments
693 users