如何查找没有父文档的 Firestore 集合?
How to find Firestore collections which don't have parent documents?
我正在尝试清理我的 Google Cloud Firestore 数据库,但我有一些没有父文档的子集合(父文档已被删除)。我如何使用 Firebase Admin SDK 找到所有这些,以便删除它们?
你最终会为此编写大量代码。我要 link 到 nodejs API。
对于每个 可能 缺少文档的集合,您将需要使用 listDocuments(). That will return a list of all documents in the collection, including the missing documents that have subcollections. You will then need to iterate the DocumentReferences returned in that list, and call get() on every one of them. The returned DocumentSnapshot 查询该集合,然后使用 listDocuments(). That will return a list of all documents in the collection, including the missing documents that have subcollections. You will then need to iterate the DocumentReferences returned in that list, and call get() on every one of them. The returned DocumentSnapshot 将告诉您它是否存在它 exists
属性.
获得所有引用缺失文档的 DocumentReference 对象后,您可以按照此 that describes how to delete all nested subcollections under that DocumentReference, go straight to the Firebase documentation.
中的说明进行操作
我正在尝试清理我的 Google Cloud Firestore 数据库,但我有一些没有父文档的子集合(父文档已被删除)。我如何使用 Firebase Admin SDK 找到所有这些,以便删除它们?
你最终会为此编写大量代码。我要 link 到 nodejs API。
对于每个 可能 缺少文档的集合,您将需要使用 listDocuments(). That will return a list of all documents in the collection, including the missing documents that have subcollections. You will then need to iterate the DocumentReferences returned in that list, and call get() on every one of them. The returned DocumentSnapshot 查询该集合,然后使用 listDocuments(). That will return a list of all documents in the collection, including the missing documents that have subcollections. You will then need to iterate the DocumentReferences returned in that list, and call get() on every one of them. The returned DocumentSnapshot 将告诉您它是否存在它 exists
属性.
获得所有引用缺失文档的 DocumentReference 对象后,您可以按照此