问题
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