Firebase增加值而不读取先前的值? [英] Firebase increase value without reading previous value?
问题描述
我正在使用Firebase开发具有大量用户的ios应用程序.我需要根据用户的响应更新Firebase数据库中的特定字段值.有没有一种方法可以将特定字段的值增加一(1),而无需读取其当前值.当多个用户试图同时增加同一字段的值时会发生什么?
I'm developing an ios application using Firebase it has huge users. I need to update particular field value in Firebase database based on user's response. Is there a way to increase particular field' value by one(1) without reading its current value. What will happen when several users trying to increase value of same field concurrently?
推荐答案
在客户端应用程序中,如果不读取值就无法增加值.如果有多个作者,则最后一个作者的值会覆盖其他所有内容.
From a client app, you cannot increment a value without reading it. If there are multiple writers, the last writer's value overwrites everything else.
If you want to safely increment a value when there are concurrent writers of the same value, use a transaction.
这篇关于Firebase增加值而不读取先前的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!