我收集了数以百万计的条目。我想有效地删除所有数据,但不删除集合。
最好的方法是什么?
db.some_coll.remove({})
需要很多时间!!!
最佳答案
What is the best way to do that?
你已经找到了。清除集合只有两种方法:
db.some_coll.remove({})
:一次删除所有内容。这需要很长时间,因为每次删除都与插入一样昂贵。db.some_coll.drop()
:简单地清除整个集合。
I want to remove efficiently all the entire data, but without dropping the collection.
为什么不放弃收藏呢?您想要删除所有数据,您所需要做的就是重新创建索引以及可能的集合上的设置(仅适用于上限集合)。
重新创建索引非常容易。 那么问题是什么?
关于performance - mongo高效地从大集合中删除数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10385941/