How can I do batch writes/run transactions with firestore in an angular2 app?
https://firebase.google.com/docs/firestore/manage-data/transactions
If it's possible, how can I convert the JS code to TS code in an angular2 app.
Each transaction or batch of writes can write to a maximum of 500 documents.
Transactional data is used when you need to return some data from the database then make some calculation with it and store it back. Let us say we have one player inside our player list. We want to retrieve property, add one year of age and return it back to Firebase.
It's simple:
constructor(private db: AngularFirestore){}
inserting(){
//--create batch--
let batch = this.db.firestore.batch();
//--create a reference--
const userRef = this.db.collection('users').doc('women').ref;
batch.set(userRef , {
name: "Maria"
});
//--create a reference--
const userRef = this.db.collection('users').doc('men').ref;
batch.set(userRef , {
name: "Diego"
});
//--Others more 54 batch's--
//--finally--
return batch.commit();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With