Thursday, April 19, 2018

Best way to drop big collection in MongoDB

Leave a Comment

I have standalone MongoDB instance version 3.2. Storage engine is WiredTiger. What is the best way to drop big collection (>500Gb) to minimize time of exclusive database lock? Will be there time difference between 2 solution?

  • Remove all documents from collection, drop index, drop collection
  • Just drop collection

Additional information, probably it could be important:

  • Collection contains about 200.000.000 documents
  • Collection has only one index by _id
  • '_id' looks like {_id : {day: "2018-01-01", key :"someuniquekeybyday"}}

1 Answers

Answers 1

The correct answer is probably: "drop operation is not linear". It takes few seconds on 10Gb collection and it takes absolutely the same time with 500Gb collection.

I've deleted 1TB collection many times, it took several seconds.

p.s. To offer you something new, not seen in comments: you have the third option - to make a copy of other collections in this database and then switch database in your application.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment