从Firestore中删除所有文档和集合

jme*_*nke 5 firebase google-cloud-firestore firebase-cli

我正在尝试清除一个Firestore数据库,该数据库中包含大量文档和子集合以供测试.Firebase CLI(firebase-tools@3.18.4)建议从Cloud Firestore删除数据的可能性如下:

用法: firestore:删除[options] [path]

选项:

-r, --recursive    Recursive. Delete all documents and subcollections. Any action which would result in the deletion of child documents will fail if this argument is not passed. May not be passed along with --shallow.
--shallow          Shallow. Delete only parent documents and ignore documents in subcollections. Any action which would orphan documents will fail if this argument is not passed. May not be passed along with -r.
--all-collections  Delete all. Deletes the entire Firestore database, including all collections and documents. Any other flags or arguments will be ignored.
-y, --yes          No confirmation. Otherwise, a confirmation prompt will appear.
Run Code Online (Sandbox Code Playgroud)

问题是它并不适合我.

执行firebase firestore:delete --all-collections产生以下输出:

You are about to delete YOUR ENTIRE DATABASE. Are you sure? Yes
Deleting the following collections: 13OPlWrRit5PoaAbM0Rk, 17lHmJpTKVn1MBBbC169, 18LvlhhaCA1tygJYqIDt, 1DgDspzJwSEZrYxeM5G6, 1GQE7ySki4MhXxAeAzpx, 1MhoDe5JZY8Lz3yd7rVl, 1NOZ7OJeqSKl38dyh5Sw, 1Rxkjpgmr3gKvYhBJX29, 1S3mAhzQMd137Eli7qAp, 1S8FZxuefpIWBGx0hJW2, 1a7viEplYa79eNNus5xC, 1cgzMxAayzSkZv2iZf6e, 1dGjESrw6j12hEOqMpky, 1dbfgFD5teTXvQ6Ym897, 1eeYQgv2BJIS0aFWPksD, 1ehWNAZ0uKwg7mPXt3go, 1fDTkbwrXmGwZlFUl3zi, 1k5bk4aiMCuPw2KvCoAl, 1pxUSDh1YqkQAcuUH9Ie, 1rMSZ5Ru0cAfdcjY0Ljy
Deleted 92 docs (652 docs/s)
Run Code Online (Sandbox Code Playgroud)

即使在多次执行该函数之后,仍然会在Firestore数据库中保留大量文档和子集合.ENTIRE DATABASE执行命令时,只删除约70-150个文档,而不是删除.

如何删除整个数据库?

jme*_*nke 2

我已将其报告为错误并收到以下答复:

目前,这是一种预期行为。正如我们的文档中所述,删除超过 500 个文档的集合需要多次批量操作。因此,进行迭代将是处理部分删除情况的好方法。我还建议您查看我们有关一些可调用函数限制的文档以获取更多详细信息。

这意味着 firebase-tools 在一项操作中始终最多删除 500 个文档。我删除数据库中所有集合和文档的解决方案是使用 while 循环:

while firebase firestore:delete --all-collections --project MYPROJECT -y; do :; done
Run Code Online (Sandbox Code Playgroud)

经过一些迭代后,您将看到没有剩余的集合,您可以停止脚本。您的 Firestore DB 现在完全为空。