From 87ffdf1f87b922198fe950203521b705575db667 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Fri, 4 Jul 2025 20:28:13 +0200 Subject: [PATCH] Update MongoDbStore.cs --- .../Elsa.Persistence.MongoDb/Common/MongoDbStore.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/modules/persistence/Elsa.Persistence.MongoDb/Common/MongoDbStore.cs b/src/modules/persistence/Elsa.Persistence.MongoDb/Common/MongoDbStore.cs index 6e6fd31b..af4371a0 100644 --- a/src/modules/persistence/Elsa.Persistence.MongoDb/Common/MongoDbStore.cs +++ b/src/modules/persistence/Elsa.Persistence.MongoDb/Common/MongoDbStore.cs @@ -134,10 +134,11 @@ public async Task SaveManyAsync(IEnumerable documents, string primary await collection.BulkWriteAsync(writes, cancellationToken: cancellationToken); } - public async Task UpdatePartialAsync( + public async Task UpdatePartialAsync( string id, IDictionary updatedFields, string primaryKey = nameof(Entity.Id), + bool throwIfNotFound = true, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(id)) @@ -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; } /// @@ -455,4 +463,4 @@ private void ApplyTenantId(IEnumerable documents) tenantDocument.TenantId = tenantId.EmptyToNull(); } } -} \ No newline at end of file +}