如何使用flutter更新Firestore中所有文档的单个字段? [英] How to update a single field of all documents in firestore using flutter?

查看:50
本文介绍了如何使用flutter更新Firestore中所有文档的单个字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中有100个用户文档,并且我必须在所有文档中将一个字段更新为0.我们该怎么做?

I have a 100 user documents in database, and I have to update one field to 0 in all documents. How do we do it?

推荐答案

Firestore不提供类似于SQL的"update where"该命令可一次更新所有内容,因此您将必须:

Firestore doesn't offer a SQL-like "update where" command that updates everything at once, so you will have to:

  1. 查询要更新的文档
  2. 迭代每个 DocumentSnapshot 并使用以下方法获取其DocumentReference对象引用属性
  3. 对于每个文档,更新该字段及其新价值
  1. Query for the documents to update
  2. Iterate each DocumentSnapshot and get its DocumentReference object using the reference property
  3. For each document, update the field with its new value

这篇关于如何使用flutter更新Firestore中所有文档的单个字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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