为什么我的所有文档都没有在Firestore中更新? [英] Why aren't all my documents updated in Firestore?

查看:67
本文介绍了为什么我的所有文档都没有在Firestore中更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python尝试将字段添加到Firestore集合中的750多个文档中,但是当尝试执行此操作时,仅更新了我的前55个文档.我认为这是由于Firestore的写入限制而导致的,但并没有真正弄清原因.

I'm using python for trying to add a field to more than 750 documents in a firestore collection, but when trying to do this, only my first 55 documents get updated. I'm assuming this happens because of the firestore write limits but don't really get why.

注意: actividades是一个数组,大小约为20个元素,每个元素只有3个属性.

Note: actividades is an array with a size around of 20 elements and each element has only 3 properties.

import firebase_admin
from firebase_admin import credentials, firestore

cred = credentials.Certificate('avancesAccountKey.json')
default_app = firebase_admin.initialize_app(cred)
db = firestore.client()

count = 0
avances = db.collection('avances').get()
for e in avances:  
    db.collection('avances').document(e.id).update({
        'vigente': False
    })
    count += 1

print(count) # count is 55 when trying to update, 757 otherwise

到底发生了什么,我该如何解决?

What is exactly happening and how I can solve this?

推荐答案

在遍历集合时,您不应对其进行突变.取而代之的是,获取文档引用,然后进行迭代.

You shouldn't mutate the collection as you iterate through it. Instead, fetch the document references and then iterate.

count = 0
documents = [snapshot.reference for snapshot in db.collection('avances').get()]
for document in documents:
    document.update({u'vigente': False})
    count += 1

参考: https://github.com/GoogleCloudPlatform/google-cloud -python/issues/6033

更新:看来Firestore python客户端确实具有

Update: It appears the Firestore python client does have a 20 second timeout for the generator returned from a query.

这篇关于为什么我的所有文档都没有在Firestore中更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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