mongo efficient remove data from big collection

By : Julias
Source: Stackoverflow.com
Question!

I have a big collection of millions entries. I want to remove efficiently all the data, but without dropping the collection.

What is the best way to do that?

db.some_coll.remove({})

takes a lot of time!!!

By : Julias


Answers
What is the best way to do that?

You have found it. There are only two ways to clear out a collection:

  1. db.some_coll.remove({}): which deletes everything one at a time. It takes a long time because each deletion is as expensive as an insert.
  2. db.some_coll.drop(): simply clears the entire collection.

I want to remove efficiently all the entire data, but without dropping the collection.

Why not drop the collection? You want to remove all of the data, all you need to do is re-create the indexes and possibly the settings on the collection (capped collections only).

Re-creating indexes is very easy. So what's the hangup?

By : Gates VP


This video can help you solving your question :)
By: admin