runTransaction method

Future<void> runTransaction(
  1. String collectionPath,
  2. String docId
)

Implementation

Future<void> runTransaction(String collectionPath, String docId) async {
  await _db.runTransaction((transaction) async {
    DocumentSnapshot snapshot = await transaction.get(_db.collection(collectionPath).doc(docId));
    if (snapshot.exists) {
      int currentCount = snapshot['count'];
      transaction.update(_db.collection(collectionPath).doc(docId), {'count': currentCount + 1});
    }
  });
}