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

后端 未结 4 1079
旧巷少年郎
旧巷少年郎 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 05:43

    Removing and Dropping a collection is mostly implementation detail.

    Removing a collection requires an one by one update of internal state that happen to exists in the collection.

    Dropping a collection requires freeing up some large data structures inside the database of data files.

    Dropping collection is vastly faster than removing one by one until collection is empty.

    Meta data like indexes will exists if the collection is removed rather than when its dropped.

    Source: MongDB University course

提交回复
热议问题