Ionic Increment Firestore Value

微笑、不失礼 提交于 2021-01-28 05:48:36

问题


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.

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?

Thanks, Troy


回答1:


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

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.



来源:https://stackoverflow.com/questions/50499829/ionic-increment-firestore-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!