updatePartially method
Updates only few selected fields in a data item.
correlation_id
(optional) transaction id to trace execution through call chain.id
an id of data item to be updated.data
a map with fields to be updated. Return Future that receives updated item Throws error.
Implementation
Future<T?> updatePartially(
String? correlationId, K? id, AnyValueMap? data) async {
if (data == null || id == null) {
return null;
}
var newItem = data.innerValue();
newItem = convertFromPublicPartial(
newItem != null ? Map<String, dynamic>.from(newItem) : null);
var filter = {'_id': id};
var update = {r'$set': newItem};
var result = await collection?.updateOne(filter, update);
if (result != null && result.ok == 1.0) {
logger.trace(correlationId, 'Updated partially in %s with id = %s',
[collectionName, id]);
return await getOneById(correlationId, id);
}
return null;
}