create method
Creates a data item.
correlation_id
(optional) transaction id to trace execution through call chain.item
an item to be created. Return Future that receives created item Throws error.
Implementation
Future<T?> create(String? correlationId, T? item) async {
if (item == null) {
return null;
}
var jsonMap = convertFromPublic(item, createUid: false);
var result = jsonMap != null ? await collection?.insert(jsonMap) : null;
if (result != null && result['ok'] == 1.0) {
logger.trace(correlationId, 'Created in %s with id = %s',
[collectionName, jsonMap!['_id']]);
return convertToPublic(jsonMap);
}
return null;
}