且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MongoDB:权衡删除集合与删除其所有文档

更新时间:2023-02-14 09:15:14

如果您要从集合中删除所有文档,那么您将要做更多的工作(释放文档的存储空间,清除索引条目指向文档,依此类推).如果您只是删除该集合,那么它将只是回收该集合及其索引使用的范围.

If you go through a remove all the documents from a collection, then you'll be doing a lot more work (freeing the document's storage, clearing the index entries that point to the document, and so on). If you instead just drop the collection, it'll just be reclaiming the extents that the collection and its indexes use.

另一个不同之处在于,删除集合还会删除集合的索引.

One other difference is that dropping the collection will also remove the collection's indexes.