Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ public async Task SaveManyAsync(IEnumerable<TDocument> documents, string primary
await collection.BulkWriteAsync(writes, cancellationToken: cancellationToken);
}

public async Task UpdatePartialAsync(
public async Task<bool> UpdatePartialAsync(
string id,
IDictionary<string, object> updatedFields,
string primaryKey = nameof(Entity.Id),
bool throwIfNotFound = true,
CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(id))
Expand All @@ -154,7 +155,14 @@ public async Task UpdatePartialAsync(
var updateResult = await collection.UpdateOneAsync(filter, updateDefinition, cancellationToken: cancellationToken);

if (updateResult.MatchedCount == 0)
{
if (!throwIfNotFound)
return false;

throw new InvalidOperationException($"No document found with ID '{id}'.");
}

return updateResult.ModifiedCount > 0;
}

/// <summary>
Expand Down Expand Up @@ -455,4 +463,4 @@ private void ApplyTenantId(IEnumerable<TDocument> documents)
tenantDocument.TenantId = tenantId.EmptyToNull();
}
}
}
}
Loading