Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I've tried

db.users.remove(*)

Although it returns an error so how do I go about clearing all records?

2 Answers

0 votes
by (106k points)

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({})

0 votes
by (108k points)

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.

Related questions

0 votes
1 answer
0 votes
2 answers
0 votes
2 answers
0 votes
2 answers
0 votes
1 answer

Browse Categories

...