如何使用python在firestore中批量删除文档

2024-05-23 18:38:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我在firestore中有一个名为XYZ的收藏。其中有500个不同字段的文档。 我必须使用where子句从集合中删除多个文档

cred = credentials.Certificate('XXXX')
app = firebase_admin.initialize_app(cred)
db = firestore.Client()

batch = db.batch()

doc_ref = db.collection('collection_name').where(u'month', '==', 07).get()

for doc in doc_ref:
      batch.delete(doc)

batch.commit()

我试过了,但最后还是出错了

AttributeError: AttributeError: 'DocumentSnapshot' object has no attribute '_document_path'

寻求帮助


Tags: 文档refappdbdocbatchcertificatewhere