update method
Updates documents in collection matching filter using MongoDB update
operators from update.
Set optimistic to true to apply the update locally immediately while
waiting for the server response.
Implementation
Future<void> update(
String collection, {
required JsonMap update,
required JsonMap filter,
bool optimistic = false,
}) async {
final updatePayload = _deepCopyMap(update);
final filterPayload = _deepCopyMap(filter);
if (updatePayload.isEmpty) {
throw ArgumentError('Update payload cannot be empty.');
}
if (optimistic) {
_queryManager.optimisticUpdate(
collection: collection,
filter: filterPayload,
update: updatePayload,
);
}
await _webSocketService.send({
'type': 'realtime:update',
'collection': collection,
'filter': filterPayload,
'update': updatePayload,
});
}