2

我收集了数百万个条目。我想有效地删除所有数据,但不删除集合。

最好的方法是什么?

db.some_coll.remove({})

需要很多时间!!!

4

1 回答 1

2

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?

于 2012-04-30T20:06:34.990 回答