首页 > 解决方案 > 事务中单个文档的多次更新是否会在 Firestore 中为每个更新分别产生写入成本

问题描述

例如将update(sfDocRef, "population", newPopulation)update(sfDocRef, "count", newCount)被视为单独的文件写入。或者我应该使用 set() 方法


db.runTransaction { transaction ->
    val snapshot = transaction.get(sfDocRef)

    val newPopulation = snapshot.getDouble("population")!! + 1
    val newCount = snapshot.getLong("count")!! + 1
    it.apply {
         update(sfDocRef, "population", newPopulation)
         update(sfDocRef, "count", newCount)
    }  
}

标签: firebasegoogle-cloud-firestoretransactions

解决方案


它被认为是一个单独的写操作。最好将它们结合起来。我想这会对你有所帮助。关联


推荐阅读