findAllWithConverter method

Future<FeedbackResponse<List<T>>> findAllWithConverter()

Finds all documents of the specified _collectionPath.

This method returns data in the form of a list of T. Make sure to have specified the _toJson and _fromJson methods or else the FirestoreApi will not now how to convert the data.

If _tryAddLocalId is true then your data will also contain a local id field based on the _idFieldName specified in the constructor. Add this id field to your T and you will have easy access to the document id at any time.

If _tryAddLocalDocumentReference is true then your data will also contain a local reference field based on the _documentReferenceFieldName specified in the constructor. Add this reference field to your T and you will have easy access to the document reference at any time.

If you rather want to retrieve data in the raw form of a List<Map<String, dynamic>> consider using the findAll method instead.

Implementation

Future<FeedbackResponse<List<T>>> findAllWithConverter() async {
  try {
    _log.info(
      message: 'Finding all documents with converter..',
      sensitiveData: _shouldNotSensitiveInfo
          ? null
          : SensitiveData(
              path: _collectionPath(),
            ),
    );
    final result = (await findCollectionWithConverter().get(_getOptions))
        .docs
        .map((e) => e.data())
        .toList();
    _logResultLength(result);
    return _responseConfig.searchSuccessResponse(
        isPlural: result.isPlural, result: result);
  } catch (error, stackTrace) {
    _log.error(
      message: 'Unable to find all documents',
      sensitiveData: _shouldNotSensitiveError
          ? null
          : SensitiveData(
              path: _collectionPath(),
            ),
      error: error,
      stackTrace: stackTrace,
    );
    return _responseConfig.searchFailedResponse(isPlural: true);
  }
}