Troy Myers
Troy Myers

Reputation: 165

Ionic Increment Firestore Value

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

Upvotes: 1

Views: 528

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599661

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.

Upvotes: 2

Related Questions