从 Cloudant 数据库中删除大量文档的最佳方法是什么?
如果您要从 Cloudant 数据库中删除大量文档(例如 200 万个),最好是批量删除调用,还是还有其他方法?
If you are deleting a large number of documents from a Cloudant database, say 2 million, is it best to batch the delete calls, or is there another approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,使用
_bulk_docs
请求批量删除是解决此问题的最佳方法。提出 200 万个单个文档删除请求是不切实际的。删除只是新文档修订版设置了已删除标志的更新。
批量大小是一个折衷方案,不要太小,以尽量减少请求数量;并且不会太大,以免给服务器带来太多工作量。一千份文件是一个合理的起点。在此示例中,仍需要 2,000 次调用才能删除所有文档。
有关如何创建批处理并发出批量删除命令的示例,请参阅
Yes, batching the deletes with a
_bulk_docs
request is the best way to approach this. Making two million single document delete requests would be impractical.Deletes are just updates where the new doc revision has the deleted flag set.
The batch size is a bit of a compromise between not too small, to minimise the number of requests; and not so large that it puts too much work on the server. A thousand documents is a reasonable starting point. In this example it would still require 2,000 calls to delete all the documents.
For an example of how to create a batch and issue a bulk delete command see this blog post.