如何递归删除Firestore中的集合? [英] How to recursively delete collection in firestore?

查看:47
本文介绍了如何递归删除Firestore中的集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种快速清除整个Firestore数据库的方法,但是找不到有关如何执行此操作的出色文档.最终,我在堆栈上发现了这个答案(清除所有数据的Firestore数据库?),但对于清除整个数以百万计的文档数据库需要花费多长时间感到有些紧张,因此我想提供一种仅一次递归删除集合的方法.

I needed a way to quickly clear an entire firestore DB but couldn't find great documentation for how to do it. Eventually I found on stack overflow this answer (Clear Firestore database of all data?) but was a bit nervous about how long it would take to clear my entire DB of millions of documents, so I want a way to just recursively delete a collection at a time.

背景:我一直在进行一些测试,以将大量数据从旧的DB迁移到Firestore,并且每次运行后,我都希望在Firestore中使用干净的板岩.不要在生产数据上使用它!

Background: I've been running some tests migrating large amounts of data from an old DB to firestore, and after each run I want a clean slate to work with in firestore. Do NOT use this on production data!

推荐答案

我能够通过运行firestore cli delete命令并按路径指定每个集合来做到这一点.确保不要以斜杠开头的路径,否则会认为您正在引用计算机上的目录.如何运行的示例:

I was able to do this by running the firestore cli delete command, specifying each collection by path. Make sure not to start the path with a leading slash, or it will think you are referring to a directory on your computer. Example of how to run:

firebase firestore:delete "path/to/collection" --recursive

firestore:delete 命令在此处也有所记录:

The firestore:delete command is sort of documented here as well: https://firebase.google.com/docs/firestore/manage-data/delete-data#delete_data_with_the_firebase_cli

更新请注意,删除约20000个文档后,该命令可能会失败.我认为这可能是一个极限.我只是使用相同的集合路径重新运行了几次,以完全删除大于2万个文档的集合.

Update Please note that the command may fail after deleting about 20000 documents. I think it might be a limit it hits. I just re-run with the same collection path a few times to fully delete collections that are larger than 20k docs.

这篇关于如何递归删除Firestore中的集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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