Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force drop a collection in MongoDB

I can't delete a collection it's telling me false every single time..

I do a getCollections() it gives me a lot of tmp.mr.mapreduce_1299189206_1618_inc (the ones I want to drop) I thought they were deleted during disconnection, but they're not (in my case).

Then when I do: db["tmp.mr.mapreduce_1299188705_5595"].drop() I always get false and it's not deleted.

The logs are not really helpful:

Wed Mar  9 11:05:51 [conn4] CMD: drop customers.tmp.mr.mapreduce_1299188705_5595

Now I maxed up my namespaces and I cannot create more collections help?

BTW, I can go down, this is not production (or even in production I can put it down too).

like image 502
igorgue Avatar asked Mar 09 '11 16:03

igorgue


People also ask

What does drop () mean MongoDB?

In MongoDB, db. collection. drop() method is used to drop a collection from a database. It completely removes a collection from the database and does not leave any indexes associated with the dropped collections.

How do you delete a collection from a database?

Delete Collection You can delete a table, or collection as it is called in MongoDB, by using the drop() method.

Which method is used to delete a collection in MongoDB?

To delete all documents from a collection, pass an empty filter document {} to the db. collection. deleteMany() method.


1 Answers

Now I maxed up my namespaces and I cannot create more collections help?

By default MongoDB has 20k namespaces, so that's a lot of dead M/R collections. According to the logs, the DB is getting the request to drop the collection. So the question now is whether or not MongoDB has gotten into a bad state.

Can you take it down and re-start to ensure that all connections are closed?

Is it a lot of data? Can you take it down and run --repair?

like image 105
Gates VP Avatar answered Oct 01 '22 04:10

Gates VP