diff --git a/src/MaksIT.MongoDB.Linq/Abstractions/BaseCollectionDataProviderBase.cs b/src/MaksIT.MongoDB.Linq/Abstractions/BaseCollectionDataProviderBase.cs index 289956f..6fda181 100644 --- a/src/MaksIT.MongoDB.Linq/Abstractions/BaseCollectionDataProviderBase.cs +++ b/src/MaksIT.MongoDB.Linq/Abstractions/BaseCollectionDataProviderBase.cs @@ -93,22 +93,15 @@ namespace MaksIT.MongoDB.Linq.Abstractions { Expression> predicate, IClientSessionHandle? session) { try { - var tasks = new List>(); - foreach (var document in documents) { - var filter = Builders.Filter.Where(predicate); - var updateOptions = new ReplaceOptions { IsUpsert = false }; - if (session != null) - tasks.Add(Collection.ReplaceOneAsync(session, filter, document, updateOptions)); + await Collection.ReplaceOneAsync(session, predicate, document); else - tasks.Add(Collection.ReplaceOneAsync(filter, document, updateOptions)); + await Collection.ReplaceOneAsync(predicate, document); } - await Task.WhenAll(tasks); - - var upsertedIds = documents.Select(doc => doc.Id).ToList(); - return Result?>.Ok(upsertedIds); + var updatedIds = documents.Select(doc => doc.Id).ToList(); + return Result?>.Ok(updatedIds); } catch (Exception ex) { Logger.LogError(ex, _errorMessage); @@ -124,12 +117,14 @@ namespace MaksIT.MongoDB.Linq.Abstractions { IClientSessionHandle? session ) { try { - var updateOptions = new ReplaceOptions { IsUpsert = true }; - - if (session != null) - await Collection.ReplaceOneAsync(session, predicate, document, updateOptions); - else - await Collection.ReplaceOneAsync(predicate, document, updateOptions); + if (session != null) { + await Collection.DeleteOneAsync(session, predicate); + await Collection.InsertOneAsync(session, document); + } + else { + await Collection.DeleteOneAsync(predicate); + await Collection.InsertOneAsync(document); + } return Result.Ok(document.Id); } @@ -146,20 +141,17 @@ namespace MaksIT.MongoDB.Linq.Abstractions { Expression> predicate, IClientSessionHandle? session) { try { - var tasks = new List>(); - foreach (var document in documents) { - var filter = Builders.Filter.Where(predicate); - var updateOptions = new ReplaceOptions { IsUpsert = true }; - - if (session != null) - tasks.Add(Collection.ReplaceOneAsync(session, filter, document, updateOptions)); - else - tasks.Add(Collection.ReplaceOneAsync(filter, document, updateOptions)); + if (session != null) { + await Collection.DeleteOneAsync(session, predicate); + await Collection.InsertOneAsync(session, document); + } + else { + await Collection.DeleteOneAsync(predicate); + await Collection.InsertOneAsync(document); + } } - await Task.WhenAll(tasks); - var upsertedIds = documents.Select(doc => doc.Id).ToList(); return Result?>.Ok(upsertedIds); } diff --git a/src/MaksIT.MongoDB.Linq/MaksIT.MongoDB.Linq.csproj b/src/MaksIT.MongoDB.Linq/MaksIT.MongoDB.Linq.csproj index 95ab6c7..69895bd 100644 --- a/src/MaksIT.MongoDB.Linq/MaksIT.MongoDB.Linq.csproj +++ b/src/MaksIT.MongoDB.Linq/MaksIT.MongoDB.Linq.csproj @@ -8,7 +8,7 @@ MaksIT.MongoDB.Linq - 1.0.0 + 1.0.1 Maksym Sadovnychyy MAKS-IT MaksIT.MongoDB.Linq