addSubCollectionDocument method

Future<String?> addSubCollectionDocument({
  1. required String collection,
  2. required String documentId,
  3. required String subCollection,
  4. required Map<String, dynamic> update,
  5. String? subCollectionDocumentId,
})

Implementation

Future<String?> addSubCollectionDocument({
  required String collection,
  required String documentId,
  required String subCollection,
  required Map<String, dynamic> update,
  String? subCollectionDocumentId,
}) async {
  try {
    final DocumentReference documentReference =
        _firebaseFirestore.collection(collection).doc(documentId).collection(subCollection).doc(subCollectionDocumentId);

    await documentReference.set(update);
    _loggingService.log(
        'FirestoreGenericService.setDocument: Set. Collection $collection, DocID: ${documentReference.id}, Update: $update');
    return documentReference.id;
  } catch (e) {
    _loggingService.log(
      'FirestoreGenericService.setDocument: Set failed. Update: $update, Exception: ${e.toString()}',
      logType: LogType.error,
    );
    return null;
  }
}