MongoDB:权衡删除集合与删除其所有文档 [英] MongoDB: Trade-offs of dropping a collection vs. removing all of its documents

查看:106
本文介绍了MongoDB:权衡删除集合与删除其所有文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

删除MongoDB集合与删除其所有文档(假设将立即重新创建集合)的权衡取舍是什么?

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

推荐答案

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

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.

这篇关于MongoDB:权衡删除集合与删除其所有文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆