离子增量Firestore价值 [英] Ionic Increment Firestore Value

查看:44
本文介绍了离子增量Firestore价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以在Firestore中使用Ionic来增加值.例如,一个喜欢"按钮,当单击一个字段值喜欢"时,会将+1添加到现有值上.

I was wondering if there was a way to increment a value in Firestore with Ionic. For example, a like button and when clicked a field value 'likes' adds +1 onto the existing value.

我看到了使用事务"完成操作的示例,但这是通过实时数据库而不是Cloud Firestore进行的.我进一步看了一下,找不到与Firestore有关的任何文档.

I saw examples with 'transactions' where this is done but it was with the Realtime Database rather than the Cloud Firestore. I looked further and could not find any documentation regarding Firestore.

总有没有不先从快照中提取现有值的情况下

Is there anyway to pull this off without pulling the existing value from the snapshot first?

谢谢,特洛伊

推荐答案

Firestore中没有服务器端增量运算符.要增加现有价值,您的应用将首先需要读取该价值.

There are no server-side increment operators in Firestore. To increase an existing value, your app will first need to read that value.

有关在Firestore中使用交易的示例,请参见更新数据在Firestore文档中进行交易.这从字面上显示了如何向字段添加1.

For an example of using a transaction in Firestore, see updating data with transactions in the Firestore documentation. This literally shows how to add 1 to a field.

这篇关于离子增量Firestore价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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