Add FindOnePipelineAsync method #2

Merged
OscarMmtz merged 1 commits from feature/add-aggregate-pipeline into development 2025-05-19 23:16:46 +00:00
2 changed files with 19 additions and 0 deletions
Showing only changes of commit b90bb23f27 - Show all commits

View File

@@ -148,5 +148,13 @@ namespace Core.Blueprint.Mongo
/// <param name="filterExpression">An expression used to filter the documents to delete.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
Task DeleteManyAsync(Expression<Func<TDocument, bool>> filterExpression);
/// <summary>
/// Executes an aggregation pipeline and returns the first document in the result asynchronously.
/// </summary>
/// <typeparam name="TOutput">The type of the output document you expect from the pipeline.</typeparam>
/// <param name="pipeline">The aggregation pipeline definition to execute.</param>
/// <returns>The first document from the aggregation result, or null if none found.</returns>
Task<TOutput> FindOnePipelineAsync<TOutput>(PipelineDefinition<TDocument, TOutput> pipeline);
}
}

View File

@@ -248,5 +248,16 @@ namespace Core.Blueprint.Mongo
{
return Task.Run(() => _collection.DeleteManyAsync(filterExpression));
}
/// <summary>
/// Executes an aggregation pipeline and returns the first document in the result asynchronously.
/// </summary>
/// <typeparam name="TOutput">The type of the output document you expect from the pipeline.</typeparam>
/// <param name="pipeline">The aggregation pipeline definition to execute.</param>
/// <returns>The first document from the aggregation result, or null if none found.</returns>
public virtual Task<TOutput> FindOnePipelineAsync<TOutput>(PipelineDefinition<TDocument, TOutput> pipeline)
{
return Task.Run(() => _collection.Aggregate(pipeline).FirstOrDefaultAsync());
}
}
}