简体   繁体   English

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

[英]how to delete documents in batch in firestore using python

I've a collection named XYZ in my firestore.我的 Firestore 中有一个名为 XYZ 的集合。 And there are 500 documents with different fields in it.其中有 500 个不同领域的文档。 I have to delete multiple documents using a where clause from the collection.我必须使用集合中的 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()

I tried this but ending up with an error我试过这个,但最终出现错误

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

Looking for help!寻求帮助!

You are passing a DocumentSnapshot object to batch.delete() , which is not allowed.您正在将 DocumentSnapshot 对象传递给batch.delete() ,这是不允许的。 You must pass a DocumentReference object instead, which can be found in a property of a DocumentSnapshot.您必须改为传递 DocumentReference 对象,该对象可以在 DocumentSnapshot 的属性中找到。

  batch.delete(doc.reference)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Python 中的 Firestore 中批量删除特定文档 - How to bulk delete specific documents from Firestore in Python 如何使用 Python 从 elasticsearch 删除获取的文档 - How delete fetched documents from elasticsearch with Python 如何使用 python 在 Firestore 中查询包含对象数组的文档 - How to query documents containing an array of objects in Firestore with python 如何使用elasticsearch python中的特定字段名称从多个索引中删除文档? - How to delete documents from multiple indices using particular field name in elasticsearch python? 如何在 python 中为 firestore 批量处理 500 多个操作? - How to batch more than 500 operations in python for firestore? 如何使用PyMongo批量删除记录 - How to batch delete records using PyMongo firestore 中是否有办法获取在 python 中使用 collection_group 查询检索到的文档的完整文档路径? - Is there a way in firestore to get full document path for documents retrieved using collection_group query in python? 使用来自第 3 方 API 的 python 将多个文档写入 Firestore - Write Multiple Documents to Firestore using python from 3rd party API 如何使用Python在Couchdb中显示所有文档 - How to display all documents in Couchdb using Python 如何使用 python 使用 Firestore 字段增量? - How to use firestore field incremental using python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM