✏️ Write to Firestore

Advanced techniques for writing data to Firestore

Writing to Firestore

file_type_flutter firestore.dart
class FirestoreService {
  /// Updates the current user's report document after completing quiz
  Future<void> updateUserReport(Quiz quiz) {
    var user = AuthService().user!;
    var ref = _db.collection('reports').doc(user.uid);

    var data = {
      'total': FieldValue.increment(1),
      'topics': {
        quiz.topic: FieldValue.arrayUnion([quiz.id])
      }
    };

    return ref.set(data, SetOptions(merge: true));
  }
}

Questions? Let's chat

Open Discord