getOneById method

  1. @override
Future<T?> getOneById(
  1. String? correlationId,
  2. K? id
)

Gets a data item by its unique id.

  • correlationId (optional) transaction id to trace execution through call chain.
  • id an id of data item to be retrieved. Return Future that receives data item Throws error.

Implementation

@override
Future<T?> getOneById(String? correlationId, K? id) async {
  var filter = {'_id': id};
  var query = mngquery.SelectorBuilder();
  var selector = <String, dynamic>{};
  selector[r'$query'] = filter;

  var item = await collection?.findOne(query.raw(selector));
  if (item == null) {
    logger.trace(correlationId, 'Nothing found from %s with id = %s',
        [collectionName, id]);
    return null;
  }
  logger.trace(
      correlationId, 'Retrieved from %s with id = %s', [collectionName, id]);

  return convertToPublic(item);
}