diff --git a/src/MongODM.Core/Repositories/IRepository.cs b/src/MongODM.Core/Repositories/IRepository.cs index 6ca4185..b3cb3d9 100644 --- a/src/MongODM.Core/Repositories/IRepository.cs +++ b/src/MongODM.Core/Repositories/IRepository.cs @@ -162,6 +162,24 @@ Task ReplaceAsync( Expression> predicate, CancellationToken cancellationToken = default); + /// + /// Find one and modify atomically with an upsert "add to set" operation. + /// Create a new document if doesn't exists, add the element to the set if not present, or do nothing if element is already present + /// + /// The document find filter + /// The set where add the item + /// The item to add + /// A new model, in case of insert + /// The cancellation token + /// Item type + /// The model as result from find before update + Task UpsertAddToSetAsync( + Expression> filter, + Expression>> setField, + TItem itemValue, + TModel onInsertModel, + CancellationToken cancellationToken = default); + /// /// Find one and modify atomically with an upsert "add to set" operation. /// Create a new document if doesn't exists, add the element to the set if not present, or do nothing if element is already present diff --git a/src/MongODM.Core/Repositories/Repository.cs b/src/MongODM.Core/Repositories/Repository.cs index ef69143..ebbb233 100644 --- a/src/MongODM.Core/Repositories/Repository.cs +++ b/src/MongODM.Core/Repositories/Repository.cs @@ -397,6 +397,19 @@ public virtual Task ReplaceAsync( } } + public Task UpsertAddToSetAsync( + Expression> filter, + Expression>> setField, + TItem itemValue, + TModel onInsertModel, + CancellationToken cancellationToken = default) => + UpsertAddToSetAsync( + new ExpressionFilterDefinition(filter), + setField, + itemValue, + onInsertModel, + cancellationToken); + public Task UpsertAddToSetAsync( FilterDefinition filter, Expression>> setField,