Twitter LogoFacebook Logo
Increment and Decrement Data in Cloud Firestore
Increment and Decrement Data in Cloud Firestore
By: King

Before you get started, you must add the FirebaseTS library to your project. Follow this tutorial to learn how to add FirebaseTS.

Once you have added FirebaseTS, you are set to go!

Incrementing and Decrementing Data

1. Import the FirebaseTSFirestore class.

import FirebaseTSFirestore from 'firebasets/firebasetsFirestore/firebaseTSFirestore';

2. Declare and initialize a FirebaseTSFirestore object.

private firestoreFirebaseTSFirestore;

constructor(){
  this.firestore new FirebaseTSFirestore();
}

3. Call the update() method to update a value that you want and then call the increment() method on the value.

this.firestore.update(
 {
   from: [
     ...
   ],
   data: {
     age: this.firestore.increment(2.5)
   }
 }
);

To decrement the value, use a negative value.

this.firestore.increment(-2)


Sign In