MongoDB: Trade-offs of dropping a collection vs. removing all of its documents

后端 未结 4 1102
旧巷少年郎
旧巷少年郎 2020-12-29 05:42

What are the trade-offs of dropping a MongoDB collection vs. removing all of its documents (assuming the collection will be re-created immediately)?

4条回答
  •  甜味超标
    2020-12-29 06:03

    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.

提交回复
热议问题