diff --git a/CoreIntegrationTests/Infrastructure/MongoDbDocumentTestBase.Main.cs b/CoreIntegrationTests/Infrastructure/MongoDbDocumentTestBase.Main.cs index 98fc846..24a5cd9 100644 --- a/CoreIntegrationTests/Infrastructure/MongoDbDocumentTestBase.Main.cs +++ b/CoreIntegrationTests/Infrastructure/MongoDbDocumentTestBase.Main.cs @@ -8,6 +8,7 @@ using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; +using MongoDB.Driver; using Xunit; namespace CoreIntegrationTests.Infrastructure @@ -228,6 +229,19 @@ public void GetOne() Assert.True(null != result, GetTestName()); } + [Fact] + public void GetFilterDefinitionCursor() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var cursor = SUT.GetCursor(Builders.Filter.Eq(x => x.Id, document.Id), partitionKey: PartitionKey); + var count = cursor.CountDocuments(); + // Assert + Assert.True(1 == count, GetTestName()); + } + [Fact] public void GetCursor() { @@ -361,6 +375,19 @@ public void DeleteOne() Assert.True(1 == result); Assert.False(SUT.Any(e => e.Id.Equals(document.Id), PartitionKey), GetTestName()); } + + [Fact] + public void DeleteOneFilterDefinition() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.DeleteOne(Builders.Filter.Eq(x => x.Id, document.Id), partitionKey: PartitionKey); + // Assert + Assert.True(1 == result); + Assert.False(SUT.Any(e => e.Id.Equals(document.Id), PartitionKey), GetTestName()); + } [Fact] public void DeleteOneLinq() @@ -388,6 +415,19 @@ public async Task DeleteOneAsync() Assert.False(SUT.Any(e => e.Id.Equals(document.Id), PartitionKey), GetTestName()); } + [Fact] + public async Task DeleteOneAsyncFilterDefinition() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.DeleteOneAsync(Builders.Filter.Eq(x => x.Id, document.Id), partitionKey: PartitionKey); + // Assert + Assert.True(1 == result); + Assert.False(SUT.Any(e => e.Id.Equals(document.Id), PartitionKey), GetTestName()); + } + [Fact] public async Task DeleteOneAsyncLinq() { @@ -401,6 +441,21 @@ public async Task DeleteOneAsyncLinq() Assert.False(SUT.Any(e => e.Id.Equals(document.Id), PartitionKey), GetTestName()); } + [Fact] + public async Task DeleteManyAsyncFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}"; + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = criteria); + SUT.AddMany(documents); + // Act + var result = await SUT.DeleteManyAsync(Builders.Filter.Eq(x => x.SomeContent, criteria), partitionKey: PartitionKey); + // Assert + Assert.True(5 == result); + Assert.False(SUT.Any(e => e.SomeContent == criteria, PartitionKey), GetTestName()); + } + [Fact] public async Task DeleteManyAsyncLinq() { @@ -444,6 +499,21 @@ public async Task DeleteManyAsync() } } + [Fact] + public void DeleteManyFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}"; + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = criteria); + SUT.AddMany(documents); + // Act + var result = SUT.DeleteMany(Builders.Filter.Eq(x => x.SomeContent, criteria), partitionKey: PartitionKey); + // Assert + Assert.True(5 == result); + Assert.False(SUT.Any(e => e.SomeContent == criteria, PartitionKey), GetTestName()); + } + [Fact] public void DeleteManyLinq() { @@ -516,6 +586,61 @@ public async Task ProjectOneAsync() Assert.True(someDate.Minute == result.SomeDate.Minute, GetTestName()); Assert.True(someDate.Second == result.SomeDate.Second, GetTestName()); } + + [Fact] + public async Task ProjectOneAsyncFilterDefinitionWithProjectionDefinition() + { + // Arrange + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var document = CreateTestDocument(); + document.SomeContent = someContent; + document.Nested.SomeDate = someDate; + SUT.AddOne(document); + + var projectionBuilder = new ProjectionDefinitionBuilder(); + // Act + var result = await SUT.ProjectOneAsync( + Builders.Filter.Eq(x => x.Id, document.Id), + projectionBuilder.Expression(x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }), + partitionKey: PartitionKey); + // Assert + Assert.True(null != result, GetTestName()); + Assert.True(someContent == result.SomeContent, GetTestName()); + Assert.True(someDate.Minute == result.SomeDate.Minute, GetTestName()); + Assert.True(someDate.Second == result.SomeDate.Second, GetTestName()); + } + + [Fact] + public async Task ProjectOneAsyncFilterDefinitionWithExpression() + { + // Arrange + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var document = CreateTestDocument(); + document.SomeContent = someContent; + document.Nested.SomeDate = someDate; + SUT.AddOne(document); + + // Act + var result = await SUT.ProjectOneAsync( + Builders.Filter.Eq(x => x.Id, document.Id), + x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }, + partitionKey: PartitionKey); + // Assert + Assert.True(null != result, GetTestName()); + Assert.True(someContent == result.SomeContent, GetTestName()); + Assert.True(someDate.Minute == result.SomeDate.Minute, GetTestName()); + Assert.True(someDate.Second == result.SomeDate.Second, GetTestName()); + } [Fact] public void ProjectOne() @@ -542,6 +667,61 @@ public void ProjectOne() Assert.True(someDate.Minute == result.SomeDate.Minute, GetTestName()); Assert.True(someDate.Second == result.SomeDate.Second, GetTestName()); } + + [Fact] + public void ProjectOneFilterDefinitionWithProjectionDefinition() + { + // Arrange + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var document = CreateTestDocument(); + document.SomeContent = someContent; + document.Nested.SomeDate = someDate; + SUT.AddOne(document); + var projectionBuilder = new ProjectionDefinitionBuilder(); + + // Act + var result = SUT.ProjectOne( + Builders.Filter.Eq(x => x.Id, document.Id), + projectionBuilder.Expression(x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }), + partitionKey: PartitionKey); + // Assert + Assert.True(null != result, GetTestName()); + Assert.True(someContent == result.SomeContent, GetTestName()); + Assert.True(someDate.Minute == result.SomeDate.Minute, GetTestName()); + Assert.True(someDate.Second == result.SomeDate.Second, GetTestName()); + } + + [Fact] + public void ProjectOneFilterDefinitionWithExpression() + { + // Arrange + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var document = CreateTestDocument(); + document.SomeContent = someContent; + document.Nested.SomeDate = someDate; + SUT.AddOne(document); + + // Act + var result = SUT.ProjectOne( + Builders.Filter.Eq(x => x.Id, document.Id), + x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }, + partitionKey: PartitionKey); + // Assert + Assert.True(null != result, GetTestName()); + Assert.True(someContent == result.SomeContent, GetTestName()); + Assert.True(someDate.Minute == result.SomeDate.Minute, GetTestName()); + Assert.True(someDate.Second == result.SomeDate.Second, GetTestName()); + } [Fact] public async Task ProjectManyAsync() @@ -572,6 +752,67 @@ public async Task ProjectManyAsync() Assert.True(someDate.Minute == result.First().SomeDate.Minute, GetTestName()); Assert.True(someDate.Second == result.First().SomeDate.Second, GetTestName()); } + + [Fact] + public async Task ProjectManyAsyncFilterDefinitionWithProjectionDefinition() + { + // Arrange + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var documents = CreateTestDocuments(5); + documents.ForEach(e => + { + e.SomeContent = someContent; + e.Nested.SomeDate = someDate; + }); + var projectionBuilder = new ProjectionDefinitionBuilder(); + + SUT.AddMany(documents); + // Act + var result = await SUT.ProjectManyAsync( + Builders.Filter.Eq(x => x.SomeContent, someContent), + projectionBuilder.Expression(x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }), + partitionKey: PartitionKey); + // Assert + Assert.True(5 == result.Count, GetTestName()); + Assert.True(someContent == result.First().SomeContent, GetTestName()); + Assert.True(someDate.Minute == result.First().SomeDate.Minute, GetTestName()); + Assert.True(someDate.Second == result.First().SomeDate.Second, GetTestName()); + } + + [Fact] + public async Task ProjectManyAsyncFilterDefinitionWithProjectionExpression() + { + // Arrange + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var documents = CreateTestDocuments(5); + documents.ForEach(e => + { + e.SomeContent = someContent; + e.Nested.SomeDate = someDate; + }); + + SUT.AddMany(documents); + // Act + var result = await SUT.ProjectManyAsync( + Builders.Filter.Eq(x => x.SomeContent, someContent), + x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }, + partitionKey: PartitionKey); + // Assert + Assert.True(5 == result.Count, GetTestName()); + Assert.True(someContent == result.First().SomeContent, GetTestName()); + Assert.True(someDate.Minute == result.First().SomeDate.Minute, GetTestName()); + Assert.True(someDate.Second == result.First().SomeDate.Second, GetTestName()); + } [Fact] public void ProjectMany() @@ -602,6 +843,67 @@ public void ProjectMany() Assert.True(someDate.Minute == result.First().SomeDate.Minute, GetTestName()); Assert.True(someDate.Second == result.First().SomeDate.Second, GetTestName()); } + + [Fact] + public void ProjectManyFilterDefinitionWithProjectionDefinition() + { + // Arrange + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var documents = CreateTestDocuments(5); + documents.ForEach(e => + { + e.SomeContent = someContent; + e.Nested.SomeDate = someDate; + }); + var projectionBuilder = new ProjectionDefinitionBuilder(); + + SUT.AddMany(documents); + // Act + var result = SUT.ProjectMany( + Builders.Filter.Eq(x => x.SomeContent, someContent), + projectionBuilder.Expression(x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }), + partitionKey: PartitionKey); + // Assert + Assert.True(5 == result.Count, GetTestName()); + Assert.True(someContent == result.First().SomeContent, GetTestName()); + Assert.True(someDate.Minute == result.First().SomeDate.Minute, GetTestName()); + Assert.True(someDate.Second == result.First().SomeDate.Second, GetTestName()); + } + + [Fact] + public void ProjectManyFilterDefinitionWithProjectionExpression() + { + // Arrange + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var documents = CreateTestDocuments(5); + documents.ForEach(e => + { + e.SomeContent = someContent; + e.Nested.SomeDate = someDate; + }); + + SUT.AddMany(documents); + // Act + var result = SUT.ProjectMany( + Builders.Filter.Eq(x => x.SomeContent, someContent), + x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }, + partitionKey: PartitionKey); + // Assert + Assert.True(5 == result.Count, GetTestName()); + Assert.True(someContent == result.First().SomeContent, GetTestName()); + Assert.True(someDate.Minute == result.First().SomeDate.Minute, GetTestName()); + Assert.True(someDate.Second == result.First().SomeDate.Second, GetTestName()); + } #endregion Project @@ -629,6 +931,30 @@ public async Task GetByMaxAsync() Assert.NotNull(result); Assert.Equal(expectedMax.Id, result.Id); } + + [Fact] + public async Task GetByMaxAsyncFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}"; + var documents = CreateTestDocuments(5); + var i = 1; + documents.ForEach(e => + { + e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); + e.SomeContent = criteria; + }); + SUT.AddMany(documents); + var expectedMax = documents.OrderByDescending(e => e.Nested.SomeDate).First(); + + // Act + var result = await SUT.GetByMaxAsync(Builders.Filter.Eq(x => x.SomeContent, criteria), e => e.Nested.SomeDate, + partitionKey: PartitionKey); + + // Assert + Assert.NotNull(result); + Assert.Equal(expectedMax.Id, result.Id); + } [Fact] public void GetByMax() @@ -652,6 +978,29 @@ public void GetByMax() Assert.NotNull(result); Assert.Equal(expectedMax.Id, result.Id); } + + [Fact] + public void GetByMaxFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}"; + var documents = CreateTestDocuments(5); + var i = 1; + documents.ForEach(e => + { + e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); + e.SomeContent = criteria; + }); + SUT.AddMany(documents); + var expectedMax = documents.OrderByDescending(e => e.Nested.SomeDate).First(); + + // Act + var result = SUT.GetByMax(Builders.Filter.Eq(x => x.SomeContent, criteria), e => e.Nested.SomeDate, partitionKey: PartitionKey); + + // Assert + Assert.NotNull(result); + Assert.Equal(expectedMax.Id, result.Id); + } [Fact] public async Task GetByMinAsync() @@ -675,6 +1024,30 @@ public async Task GetByMinAsync() Assert.NotNull(result); Assert.Equal(expectedMin.Id, result.Id); } + + [Fact] + public async Task GetByMinAsyncFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}"; + var documents = CreateTestDocuments(5); + var i = 1; + documents.ForEach(e => + { + e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); + e.SomeContent = criteria; + }); + SUT.AddMany(documents); + var expectedMin = documents.OrderBy(e => e.Nested.SomeDate).First(); + + // Act + var result = await SUT.GetByMinAsync(Builders.Filter.Eq(x => x.SomeContent, criteria), e => e.Nested.SomeDate, + partitionKey: PartitionKey); + + // Assert + Assert.NotNull(result); + Assert.Equal(expectedMin.Id, result.Id); + } [Fact] public void GetByMin() @@ -698,6 +1071,30 @@ public void GetByMin() Assert.NotNull(result); Assert.Equal(expectedMin.Id, result.Id); } + + [Fact] + public void GetByMinFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}"; + var documents = CreateTestDocuments(5); + var i = 1; + documents.ForEach(e => + { + e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); + e.SomeContent = criteria; + }); + SUT.AddMany(documents); + var expectedMin = documents.OrderBy(e => e.Nested.SomeDate).First(); + + // Act + var result = SUT.GetByMin(Builders.Filter.Eq(x => x.SomeContent, criteria), e => e.Nested.SomeDate, + partitionKey: PartitionKey); + + // Assert + Assert.NotNull(result); + Assert.Equal(expectedMin.Id, result.Id); + } [Fact] public void GetMinValue() @@ -721,6 +1118,30 @@ public void GetMinValue() Assert.True(result != default(DateTime)); Assert.Equal(expectedMin.Nested.SomeDate.Date, result.Date); } + + [Fact] + public void GetMinValueFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}"; + var documents = CreateTestDocuments(5); + var i = 1; + documents.ForEach(e => + { + e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); + e.SomeContent = criteria; + }); + SUT.AddMany(documents); + var expectedMin = documents.OrderBy(e => e.Nested.SomeDate).First(); + + // Act + var result = SUT.GetMinValue(Builders.Filter.Eq(x => x.SomeContent, criteria), e => e.Nested.SomeDate, + partitionKey: PartitionKey); + + // Assert + Assert.True(result != default(DateTime)); + Assert.Equal(expectedMin.Nested.SomeDate.Date, result.Date); + } [Fact] public async Task GetMinValueAsync() @@ -744,6 +1165,30 @@ public async Task GetMinValueAsync() Assert.True(result != default(DateTime)); Assert.Equal(expectedMin.Nested.SomeDate.Date, result.Date); } + + [Fact] + public async Task GetMinValueAsyncFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}"; + var documents = CreateTestDocuments(5); + var i = 1; + documents.ForEach(e => + { + e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); + e.SomeContent = criteria; + }); + SUT.AddMany(documents); + var expectedMin = documents.OrderBy(e => e.Nested.SomeDate).First(); + + // Act + var result = await SUT.GetMinValueAsync(Builders.Filter.Eq(x => x.SomeContent, criteria), + e => e.Nested.SomeDate, partitionKey: PartitionKey); + + // Assert + Assert.True(result != default(DateTime)); + Assert.Equal(expectedMin.Nested.SomeDate.Date, result.Date); + } [Fact] public void GetMaxValue() @@ -767,6 +1212,30 @@ public void GetMaxValue() Assert.True(result != default(DateTime)); Assert.Equal(expectedMax.Nested.SomeDate.Date, result.Date); } + + [Fact] + public void GetMaxValueFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}"; + var documents = CreateTestDocuments(5); + var i = 1; + documents.ForEach(e => + { + e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); + e.SomeContent = criteria; + }); + SUT.AddMany(documents); + var expectedMax = documents.OrderByDescending(e => e.Nested.SomeDate).First(); + + // Act + var result = SUT.GetMaxValue(Builders.Filter.Eq(x => x.SomeContent, criteria), e => e.Nested.SomeDate, + partitionKey: PartitionKey); + + // Assert + Assert.True(result != default(DateTime)); + Assert.Equal(expectedMax.Nested.SomeDate.Date, result.Date); + } [Fact] public async Task GetMaxValueAsync() @@ -790,6 +1259,30 @@ public async Task GetMaxValueAsync() Assert.True(result != default(DateTime)); Assert.Equal(expectedMin.Nested.SomeDate.Date, result.Date); } + + [Fact] + public async Task GetMaxValueAsyncFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}"; + var documents = CreateTestDocuments(5); + var i = 1; + documents.ForEach(e => + { + e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); + e.SomeContent = criteria; + }); + SUT.AddMany(documents); + var expectedMin = documents.OrderByDescending(e => e.Nested.SomeDate).First(); + + // Act + var result = await SUT.GetMaxValueAsync(Builders.Filter.Eq(x => x.SomeContent, criteria), + e => e.Nested.SomeDate, partitionKey: PartitionKey); + + // Assert + Assert.True(result != default(DateTime)); + Assert.Equal(expectedMin.Nested.SomeDate.Date, result.Date); + } #endregion Max / Min Queries diff --git a/CoreIntegrationTests/Infrastructure/MongoDbTKeyDocumentTestBase.Main.cs b/CoreIntegrationTests/Infrastructure/MongoDbTKeyDocumentTestBase.Main.cs index 1162a32..06dc97c 100644 --- a/CoreIntegrationTests/Infrastructure/MongoDbTKeyDocumentTestBase.Main.cs +++ b/CoreIntegrationTests/Infrastructure/MongoDbTKeyDocumentTestBase.Main.cs @@ -266,6 +266,19 @@ public void GetCursor() Assert.True(1 == count, GetTestName()); } + [Fact] + public void GetCursorFilterDefinition() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var cursor = SUT.GetCursor(Builders.Filter.Eq(x => x.Id, document.Id), partitionKey: PartitionKey); + var count = cursor.CountDocuments(); + // Assert + Assert.True(1 == count, GetTestName()); + } + [Fact] public async Task AnyAsyncByDefinitionReturnsTrue() { @@ -503,6 +516,19 @@ public void DeleteOneLinq() Assert.True(1 == result); Assert.False(SUT.Any(e => e.Id.Equals(document.Id), PartitionKey), GetTestName()); } + + [Fact] + public void DeleteOneFilterDefinition() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.DeleteOne(Builders.Filter.Eq(x => x.Id, document.Id), partitionKey: PartitionKey); + // Assert + Assert.True(1 == result); + Assert.False(SUT.Any(e => e.Id.Equals(document.Id), PartitionKey), GetTestName()); + } [Fact] public async Task DeleteOneAsync() @@ -529,6 +555,19 @@ public async Task DeleteOneAsyncLinq() Assert.True(1 == result); Assert.False(SUT.Any(e => e.Id.Equals(document.Id), PartitionKey), GetTestName()); } + + [Fact] + public async Task DeleteOneAsyncFilterDefinition() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.DeleteOneAsync(Builders.Filter.Eq(x => x.Id, document.Id), partitionKey: PartitionKey); + // Assert + Assert.True(1 == result); + Assert.False(SUT.Any(e => e.Id.Equals(document.Id), PartitionKey), GetTestName()); + } [Fact] public async Task DeleteManyAsyncLinq() @@ -544,6 +583,21 @@ public async Task DeleteManyAsyncLinq() Assert.True(5 == result); Assert.False(SUT.Any(e => e.SomeContent == criteria, PartitionKey), GetTestName()); } + + [Fact] + public async Task DeleteManyAsyncFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}"; + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = criteria); + SUT.AddMany(documents); + // Act + var result = await SUT.DeleteManyAsync(Builders.Filter.Eq(x => x.SomeContent, criteria), partitionKey: PartitionKey); + // Assert + Assert.True(5 == result); + Assert.False(SUT.Any(e => e.SomeContent == criteria, PartitionKey), GetTestName()); + } [Fact] public async Task DeleteManyAsync() @@ -587,6 +641,21 @@ public void DeleteManyLinq() Assert.True(5 == result); Assert.False(SUT.Any(e => e.SomeContent == criteria, PartitionKey), GetTestName()); } + + [Fact] + public void DeleteManyFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}"; + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = criteria); + SUT.AddMany(documents); + // Act + var result = SUT.DeleteMany(Builders.Filter.Eq(x => x.SomeContent, criteria), partitionKey: PartitionKey); + // Assert + Assert.True(5 == result); + Assert.False(SUT.Any(e => e.SomeContent == criteria, PartitionKey), GetTestName()); + } [Fact] public void DeleteMany() @@ -645,6 +714,59 @@ public async Task ProjectOneAsync() Assert.True(someDate.Minute == result.SomeDate.Minute, GetTestName()); Assert.True(someDate.Second == result.SomeDate.Second, GetTestName()); } + + [Fact] + public async Task ProjectOneAsyncFilterDefinitionProjectDefinition() + { + // Arrange + var projectionBuilder = new ProjectionDefinitionBuilder(); + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var document = CreateTestDocument(); + document.SomeContent = someContent; + document.Nested.SomeDate = someDate; + SUT.AddOne(document); + // Act + var result = await SUT.ProjectOneAsync( + Builders.Filter.Eq(x => x.Id, document.Id), + projectionBuilder.Expression(x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }), + partitionKey: PartitionKey); + // Assert + Assert.True(null != result, GetTestName()); + Assert.True(someContent == result.SomeContent, GetTestName()); + Assert.True(someDate.Minute == result.SomeDate.Minute, GetTestName()); + Assert.True(someDate.Second == result.SomeDate.Second, GetTestName()); + } + + [Fact] + public async Task ProjectOneAsyncFilterDefinitionProjectExpression() + { + // Arrange + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var document = CreateTestDocument(); + document.SomeContent = someContent; + document.Nested.SomeDate = someDate; + SUT.AddOne(document); + // Act + var result = await SUT.ProjectOneAsync( + Builders.Filter.Eq(x => x.Id, document.Id), + x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }, + partitionKey: PartitionKey); + // Assert + Assert.True(null != result, GetTestName()); + Assert.True(someContent == result.SomeContent, GetTestName()); + Assert.True(someDate.Minute == result.SomeDate.Minute, GetTestName()); + Assert.True(someDate.Second == result.SomeDate.Second, GetTestName()); + } [Fact] public void ProjectOne() @@ -671,6 +793,59 @@ public void ProjectOne() Assert.True(someDate.Minute == result.SomeDate.Minute, GetTestName()); Assert.True(someDate.Second == result.SomeDate.Second, GetTestName()); } + + [Fact] + public void ProjectOneFilterDefinitionProjectDefinition() + { + // Arrange + var projectionBuilder = new ProjectionDefinitionBuilder(); + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var document = CreateTestDocument(); + document.SomeContent = someContent; + document.Nested.SomeDate = someDate; + SUT.AddOne(document); + // Act + var result = SUT.ProjectOne( + Builders.Filter.Eq(x => x.Id, document.Id), + projectionBuilder.Expression(x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }), + partitionKey: PartitionKey); + // Assert + Assert.True(null != result, GetTestName()); + Assert.True(someContent == result.SomeContent, GetTestName()); + Assert.True(someDate.Minute == result.SomeDate.Minute, GetTestName()); + Assert.True(someDate.Second == result.SomeDate.Second, GetTestName()); + } + + [Fact] + public void ProjectOneFilterDefinitionProjectExpression() + { + // Arrange + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var document = CreateTestDocument(); + document.SomeContent = someContent; + document.Nested.SomeDate = someDate; + SUT.AddOne(document); + // Act + var result = SUT.ProjectOne( + Builders.Filter.Eq(x => x.Id, document.Id), + x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }, + partitionKey: PartitionKey); + // Assert + Assert.True(null != result, GetTestName()); + Assert.True(someContent == result.SomeContent, GetTestName()); + Assert.True(someDate.Minute == result.SomeDate.Minute, GetTestName()); + Assert.True(someDate.Second == result.SomeDate.Second, GetTestName()); + } [Fact] public async Task ProjectManyAsync() @@ -701,6 +876,67 @@ public async Task ProjectManyAsync() Assert.True(someDate.Minute == result.First().SomeDate.Minute, GetTestName()); Assert.True(someDate.Second == result.First().SomeDate.Second, GetTestName()); } + + [Fact] + public async Task ProjectManyAsyncFilterDefinitionProjectDefinition() + { + // Arrange + var projectionBuilder = new ProjectionDefinitionBuilder(); + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var documents = CreateTestDocuments(5); + documents.ForEach(e => + { + e.SomeContent = someContent; + e.Nested.SomeDate = someDate; + }); + + SUT.AddMany(documents); + // Act + var result = await SUT.ProjectManyAsync( + Builders.Filter.Eq(x => x.SomeContent, someContent), + projectionBuilder.Expression(x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }), + partitionKey: PartitionKey); + // Assert + Assert.True(5 == result.Count, GetTestName()); + Assert.True(someContent == result.First().SomeContent, GetTestName()); + Assert.True(someDate.Minute == result.First().SomeDate.Minute, GetTestName()); + Assert.True(someDate.Second == result.First().SomeDate.Second, GetTestName()); + } + + [Fact] + public async Task ProjectManyAsyncFilterDefinitionProjectExpression() + { + // Arrange + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var documents = CreateTestDocuments(5); + documents.ForEach(e => + { + e.SomeContent = someContent; + e.Nested.SomeDate = someDate; + }); + + SUT.AddMany(documents); + // Act + var result = await SUT.ProjectManyAsync( + Builders.Filter.Eq(x => x.SomeContent, someContent), + x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }, + partitionKey: PartitionKey); + // Assert + Assert.True(5 == result.Count, GetTestName()); + Assert.True(someContent == result.First().SomeContent, GetTestName()); + Assert.True(someDate.Minute == result.First().SomeDate.Minute, GetTestName()); + Assert.True(someDate.Second == result.First().SomeDate.Second, GetTestName()); + } [Fact] public void ProjectMany() @@ -731,6 +967,67 @@ public void ProjectMany() Assert.True(someDate.Minute == result.First().SomeDate.Minute, GetTestName()); Assert.True(someDate.Second == result.First().SomeDate.Second, GetTestName()); } + + [Fact] + public void ProjectManyFilterDefinitionProjectDefinition() + { + // Arrange + var projectionBuilder = new ProjectionDefinitionBuilder(); + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var documents = CreateTestDocuments(5); + documents.ForEach(e => + { + e.SomeContent = someContent; + e.Nested.SomeDate = someDate; + }); + + SUT.AddMany(documents); + // Act + var result = SUT.ProjectMany( + Builders.Filter.Eq(x => x.SomeContent, someContent), + projectionBuilder.Expression(x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }), + partitionKey:PartitionKey); + // Assert + Assert.True(5 == result.Count, GetTestName()); + Assert.True(someContent == result.First().SomeContent, GetTestName()); + Assert.True(someDate.Minute == result.First().SomeDate.Minute, GetTestName()); + Assert.True(someDate.Second == result.First().SomeDate.Second, GetTestName()); + } + + [Fact] + public void ProjectManyFilterDefinitionProjectExpression() + { + // Arrange + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var documents = CreateTestDocuments(5); + documents.ForEach(e => + { + e.SomeContent = someContent; + e.Nested.SomeDate = someDate; + }); + + SUT.AddMany(documents); + // Act + var result = SUT.ProjectMany( + Builders.Filter.Eq(x => x.SomeContent, someContent), + x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }, + partitionKey:PartitionKey); + // Assert + Assert.True(5 == result.Count, GetTestName()); + Assert.True(someContent == result.First().SomeContent, GetTestName()); + Assert.True(someDate.Minute == result.First().SomeDate.Minute, GetTestName()); + Assert.True(someDate.Second == result.First().SomeDate.Second, GetTestName()); + } #endregion Project @@ -759,6 +1056,29 @@ public async Task GetByMaxAsync() Assert.Equal(expectedMax.Id, result.Id); } + [Fact] + public async Task GetByMaxAsyncFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}"; + var documents = CreateTestDocuments(5); + var i = 1; + documents.ForEach(e => + { + e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); + e.SomeContent = criteria; + }); + SUT.AddMany(documents); + var expectedMax = documents.OrderByDescending(e => e.Nested.SomeDate).First(); + + // Act + var result = await SUT.GetByMaxAsync( Builders.Filter.Eq(e => e.SomeContent, criteria), e => e.Nested.SomeDate, partitionKey: PartitionKey); + + // Assert + Assert.NotNull(result); + Assert.Equal(expectedMax.Id, result.Id); + } + [Fact] public void GetByMax() { @@ -781,6 +1101,29 @@ public void GetByMax() Assert.NotNull(result); Assert.Equal(expectedMax.Id, result.Id); } + + [Fact] + public void GetByMaxFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}"; + var documents = CreateTestDocuments(5); + var i = 1; + documents.ForEach(e => + { + e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); + e.SomeContent = criteria; + }); + SUT.AddMany(documents); + var expectedMax = documents.OrderByDescending(e => e.Nested.SomeDate).First(); + + // Act + var result = SUT.GetByMax(Builders.Filter.Eq(e => e.SomeContent, criteria), e => e.Nested.SomeDate, partitionKey: PartitionKey); + + // Assert + Assert.NotNull(result); + Assert.Equal(expectedMax.Id, result.Id); + } [Fact] public void GetMaxValue() @@ -804,6 +1147,29 @@ public void GetMaxValue() Assert.False(result == default(DateTime)); Assert.Equal(expectedMax.Nested.SomeDate.Date, result.Date); } + + [Fact] + public void GetMaxValueFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}"; + var documents = CreateTestDocuments(5); + var i = 1; + documents.ForEach(e => + { + e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); + e.SomeContent = criteria; + }); + SUT.AddMany(documents); + var expectedMax = documents.OrderByDescending(e => e.Nested.SomeDate).First(); + + // Act + var result = SUT.GetMaxValue(Builders.Filter.Eq(e => e.SomeContent, criteria), e => e.Nested.SomeDate, partitionKey: PartitionKey); + + // Assert + Assert.False(result == default(DateTime)); + Assert.Equal(expectedMax.Nested.SomeDate.Date, result.Date); + } [Fact] public async Task GetMaxValueAsync() @@ -827,6 +1193,30 @@ public async Task GetMaxValueAsync() Assert.False(result == default(DateTime)); Assert.Equal(expectedMax.Nested.SomeDate.Date, result.Date); } + + [Fact] + public async Task GetMaxValueAsyncFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}"; + var documents = CreateTestDocuments(5); + var i = 1; + documents.ForEach(e => + { + e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); + e.SomeContent = criteria; + }); + SUT.AddMany(documents); + var expectedMax = documents.OrderByDescending(e => e.Nested.SomeDate).First(); + + // Act + var result = await SUT.GetMaxValueAsync(Builders.Filter.Eq(e => e.SomeContent, criteria), + e => e.Nested.SomeDate, partitionKey: PartitionKey); + + // Assert + Assert.False(result == default(DateTime)); + Assert.Equal(expectedMax.Nested.SomeDate.Date, result.Date); + } [Fact] public async Task GetByMinAsync() @@ -850,6 +1240,30 @@ public async Task GetByMinAsync() Assert.NotNull(result); Assert.Equal(expectedMin.Id, result.Id); } + + [Fact] + public async Task GetByMinAsyncFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}"; + var documents = CreateTestDocuments(5); + var i = 1; + documents.ForEach(e => + { + e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); + e.SomeContent = criteria; + }); + SUT.AddMany(documents); + var expectedMin = documents.OrderBy(e => e.Nested.SomeDate).First(); + + // Act + var result = await SUT.GetByMinAsync(Builders.Filter.Eq(e => e.SomeContent, criteria), e => e.Nested.SomeDate, + partitionKey: PartitionKey); + + // Assert + Assert.NotNull(result); + Assert.Equal(expectedMin.Id, result.Id); + } [Fact] public void GetByMin() @@ -873,6 +1287,30 @@ public void GetByMin() Assert.NotNull(result); Assert.Equal(expectedMin.Id, result.Id); } + + [Fact] + public void GetByMinFilterCriteria() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}"; + var documents = CreateTestDocuments(5); + var i = 1; + documents.ForEach(e => + { + e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); + e.SomeContent = criteria; + }); + SUT.AddMany(documents); + var expectedMin = documents.OrderBy(e => e.Nested.SomeDate).First(); + + // Act + var result = SUT.GetByMin(Builders.Filter.Eq(e => e.SomeContent, criteria), e => e.Nested.SomeDate, + partitionKey: PartitionKey); + + // Assert + Assert.NotNull(result); + Assert.Equal(expectedMin.Id, result.Id); + } [Fact] public void GetMinValue() @@ -896,6 +1334,30 @@ public void GetMinValue() Assert.True(result != default(DateTime)); Assert.Equal(expectedMin.Nested.SomeDate.Date, result.Date); } + + [Fact] + public void GetMinValueFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}"; + var documents = CreateTestDocuments(5); + var i = 1; + documents.ForEach(e => + { + e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); + e.SomeContent = criteria; + }); + SUT.AddMany(documents); + var expectedMin = documents.OrderBy(e => e.Nested.SomeDate).First(); + + // Act + var result = SUT.GetMinValue(Builders.Filter.Eq(e => e.SomeContent, criteria), e => e.Nested.SomeDate, + partitionKey: PartitionKey); + + // Assert + Assert.True(result != default(DateTime)); + Assert.Equal(expectedMin.Nested.SomeDate.Date, result.Date); + } [Fact] public async Task GetMinValueAsync() @@ -919,6 +1381,30 @@ public async Task GetMinValueAsync() Assert.True(result != default(DateTime)); Assert.Equal(expectedMin.Nested.SomeDate.Date, result.Date); } + + [Fact] + public async Task GetMinValueAsyncFilterDefinition() + { + // Arrange + var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}"; + var documents = CreateTestDocuments(5); + var i = 1; + documents.ForEach(e => + { + e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); + e.SomeContent = criteria; + }); + SUT.AddMany(documents); + var expectedMin = documents.OrderBy(e => e.Nested.SomeDate).First(); + + // Act + var result = await SUT.GetMinValueAsync(Builders.Filter.Eq(e => e.SomeContent, criteria), + e => e.Nested.SomeDate, partitionKey: PartitionKey); + + // Assert + Assert.True(result != default(DateTime)); + Assert.Equal(expectedMin.Nested.SomeDate.Date, result.Date); + } #endregion Max / Min Queries @@ -1230,6 +1716,46 @@ public async Task GetSortedPaginatedAsync() Assert.True(!result.Contains(notExpected)); Assert.Equal(expectedFirstResult.Id, result[0].Id); } + + [Fact] + public async Task GetSortedPaginatedAsyncFilterDefinition() + { + // Arrange + var content = $"{Guid.NewGuid()}"; + var documents = CreateTestDocuments(10); + for (var i = 0; i < 5; i++) + { + documents[i].GroupingKey = 8; + documents[i].Nested.SomeAmount = Random.Next(1, 500000); + documents[i].SomeContent = content; + } + for (var i = 5; i < documents.Count; i++) + { + documents[i].GroupingKey = 9; + documents[i].SomeContent = content; + } + SUT.AddMany(documents); + + documents = documents.OrderByDescending(e => e.Nested.SomeAmount).ToList(); + var notExpected = documents.First(); + var expectedFirstResult = documents[1]; + + // Act + var condition = Builders.Filter.And(Builders.Filter.Eq(x => x.GroupingKey, 8), + Builders.Filter.Eq(x => x.SomeContent, content)); + var result = await SUT.GetSortedPaginatedAsync( + condition, + e => e.Nested.SomeAmount, + null, + false, + 1,5, + PartitionKey); + + // Assert + Assert.Equal(4, result.Count); + Assert.True(!result.Contains(notExpected)); + Assert.Equal(expectedFirstResult.Id, result[0].Id); + } [Fact] public async Task GetSortedPaginatedAsyncWithSortOptions() @@ -1267,6 +1793,46 @@ public async Task GetSortedPaginatedAsyncWithSortOptions() Assert.True(!result.Contains(notExpected)); Assert.Equal(expectedFirstResult.Id, result[0].Id); } + + [Fact] + public async Task GetSortedPaginatedAsyncFilterDefinitionWithSortOptions() + { + // Arrange + var content = $"{Guid.NewGuid()}"; + var documents = CreateTestDocuments(10); + for (var i = 0; i < 5; i++) + { + documents[i].GroupingKey = 8; + documents[i].Nested.SomeAmount = Random.Next(1, 500000); + documents[i].SomeContent = content; + } + for (var i = 5; i < documents.Count; i++) + { + documents[i].GroupingKey = 9; + documents[i].SomeContent = content; + } + SUT.AddMany(documents); + + documents = documents.OrderByDescending(e => e.Nested.SomeAmount).ToList(); + var notExpected = documents.First(); + var expectedFirstResult = documents[1]; + var sorting = Builders.Sort.Descending(e => e.Nested.SomeAmount); + + // Act + var condition = Builders.Filter.And(Builders.Filter.Eq(x => x.GroupingKey, 8), + Builders.Filter.Eq(x => x.SomeContent, content)); + var result = await SUT.GetSortedPaginatedAsync( + condition, + sorting, + null, + 1, 5, + PartitionKey); + + // Assert + Assert.Equal(4, result.Count); + Assert.True(!result.Contains(notExpected)); + Assert.Equal(expectedFirstResult.Id, result[0].Id); + } #endregion Pagination diff --git a/MongoDbGenericRepository/Abstractions/IBaseMongoRepository.cs b/MongoDbGenericRepository/Abstractions/IBaseMongoRepository.cs index f163354..70f740b 100644 --- a/MongoDbGenericRepository/Abstractions/IBaseMongoRepository.cs +++ b/MongoDbGenericRepository/Abstractions/IBaseMongoRepository.cs @@ -17,6 +17,18 @@ public interface IBaseMongoRepository : IBaseMongoRepository_Delete, IBaseMongoRepository_Index { + /// + /// Asynchronously returns a paginated list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// The number of documents you want to skip. Default value is 0. + /// The number of documents you want to take. Default value is 50. + /// An optional partition key. + Task> GetPaginatedAsync(FilterDefinition condition, FindOptions findOption = null, int skipNumber = 0, int takeNumber = 50, string partitionKey = null) + where TDocument : IDocument; + /// /// Asynchronously returns a paginated list of the documents matching the filter condition. /// @@ -28,6 +40,20 @@ public interface IBaseMongoRepository : Task> GetPaginatedAsync(Expression> filter, int skipNumber = 0, int takeNumber = 50, string partitionKey = null) where TDocument : IDocument; + /// + /// Asynchronously returns a paginated list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// The number of documents you want to skip. Default value is 0. + /// The number of documents you want to take. Default value is 50. + /// An optional partition key. + Task> GetPaginatedAsync(FilterDefinition condition, FindOptions findOption = null, int skipNumber = 0, int takeNumber = 50, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Asynchronously returns a paginated list of the documents matching the filter condition. /// diff --git a/MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs b/MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs index 185ef77..281508f 100644 --- a/MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs +++ b/MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs @@ -96,6 +96,18 @@ TDocument GetOne(Expression> filter, stri where TDocument : IDocument where TKey : IEquatable; + /// + /// Returns a collection cursor. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + IFindFluent GetCursor(FilterDefinition condition, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Returns a collection cursor. /// @@ -253,6 +265,24 @@ long Count(Expression> filter, string par #region Min / Max + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// A mongodb filter definition. + /// A property selector to order by descending. + /// A mongodb filter option. + /// An optional partitionKey. + /// An optional cancellation Token. + Task GetByMaxAsync( + FilterDefinition condition, + Expression> maxValueSelector, + FindOptions findOption = null, + string partitionKey = null, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -269,6 +299,19 @@ Task GetByMaxAsync( where TDocument : IDocument where TKey : IEquatable; + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// A mongodb filter definition. + /// A property selector to order by descending. + /// A mongodb filter option. + /// An optional partitionKey. + TDocument GetByMax(FilterDefinition condition, Expression> orderByDescending, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -281,6 +324,24 @@ TDocument GetByMax(Expression> filter, Ex where TDocument : IDocument where TKey : IEquatable; + /// + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// A mongodb filter definition. + /// A property selector for the minimum value you are looking for. + /// A mongodb filter option. + /// An optional partitionKey. + /// An optional cancellation Token. + Task GetByMinAsync(FilterDefinition condition, + Expression> minValueSelector, + FindOptions findOption = null, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -297,6 +358,19 @@ Task GetByMinAsync(Expression> where TDocument : IDocument where TKey : IEquatable; + /// + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// A mongodb filter definition. + /// A property selector for the minimum value you are looking for. + /// A mongodb filter option. + /// An optional partitionKey. + TDocument GetByMin(FilterDefinition condition, Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -309,6 +383,26 @@ TDocument GetByMin(Expression> filter, Ex where TDocument : IDocument where TKey : IEquatable; + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector for the maximum value you are looking for. + /// A mongodb filter option. + /// An optional partitionKey. + /// An optional cancellation Token. + Task GetMaxValueAsync( + FilterDefinition condition, + Expression> maxValueSelector, + FindOptions findOption = null, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// @@ -327,6 +421,20 @@ Task GetMaxValueAsync( where TDocument : IDocument where TKey : IEquatable; + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partitionKey. + TValue GetMaxValue(FilterDefinition condition, Expression> maxValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// @@ -340,6 +448,26 @@ TValue GetMaxValue(Expression> fi where TDocument : IDocument where TKey : IEquatable; + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + Task GetMinValueAsync( + FilterDefinition condition, + Expression> minValueSelector, + FindOptions findOption = null, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// @@ -358,6 +486,20 @@ Task GetMinValueAsync( where TDocument : IDocument where TKey : IEquatable; + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partition key. + TValue GetMinValue(FilterDefinition condition, Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// @@ -437,6 +579,48 @@ decimal SumBy(Expression> filter, #region Project TKey + /// + /// Asynchronously returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A projection definition. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + Task ProjectOneAsync( + FilterDefinition condition, + ProjectionDefinition projection, + FindOptions findOption = null, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Asynchronously returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + Task ProjectOneAsync( + FilterDefinition condition, + Expression> projection, + FindOptions findOption = null, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + /// /// Asynchronously returns a projected document matching the filter condition. /// @@ -456,6 +640,36 @@ Task ProjectOneAsync( where TKey : IEquatable where TProjection : class; + /// + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A projection definition. + /// A mongodb filter option. + /// An optional partition key. + TProjection ProjectOne(FilterDefinition condition, ProjectionDefinition projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + TProjection ProjectOne(FilterDefinition condition, Expression> projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + /// /// Returns a projected document matching the filter condition. /// @@ -470,6 +684,48 @@ TProjection ProjectOne(Expression where TProjection : class; + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A projection definition. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + Task> ProjectManyAsync( + FilterDefinition condition, + ProjectionDefinition projection, + FindOptions findOption = null, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + Task> ProjectManyAsync( + FilterDefinition condition, + Expression> projection, + FindOptions findOption = null, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + /// /// Asynchronously returns a list of projected documents matching the filter condition. /// @@ -489,6 +745,36 @@ Task> ProjectManyAsync( where TKey : IEquatable where TProjection : class; + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A projection definition. + /// A mongodb filter option. + /// An optional partition key. + List ProjectMany(FilterDefinition condition, ProjectionDefinition projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + List ProjectMany(FilterDefinition condition, Expression> projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + /// /// Asynchronously returns a list of projected documents matching the filter condition. /// @@ -551,6 +837,29 @@ List GroupBy( #region Pagination + /// + /// Asynchronously returns a paginated list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// The property selector. + /// A mongodb filter option. + /// Order of the sorting. + /// The number of documents you want to skip. Default value is 0. + /// The number of documents you want to take. Default value is 50. + /// An optional partition key. + Task> GetSortedPaginatedAsync( + FilterDefinition condition, + Expression> sortSelector, + FindOptions findOption = null, + bool ascending = true, + int skipNumber = 0, + int takeNumber = 50, + string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Asynchronously returns a paginated list of the documents matching the filter condition. /// @@ -572,6 +881,29 @@ Task> GetSortedPaginatedAsync( where TDocument : IDocument where TKey : IEquatable; + /// + /// Asynchronously returns a paginated list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// The sort definition. + /// A mongodb filter option. + /// The number of documents you want to skip. Default value is 0. + /// The number of documents you want to take. Default value is 50. + /// An optional partition key. + /// An optional cancellation Token. + Task> GetSortedPaginatedAsync( + FilterDefinition condition, + SortDefinition sortDefinition, + FindOptions findOption = null, + int skipNumber = 0, + int takeNumber = 50, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Asynchronously returns a paginated list of the documents matching the filter condition. /// diff --git a/MongoDbGenericRepository/Abstractions/IReadOnlyMongoRepository.TKey.cs b/MongoDbGenericRepository/Abstractions/IReadOnlyMongoRepository.TKey.cs index a61374c..bc36258 100644 --- a/MongoDbGenericRepository/Abstractions/IReadOnlyMongoRepository.TKey.cs +++ b/MongoDbGenericRepository/Abstractions/IReadOnlyMongoRepository.TKey.cs @@ -45,6 +45,15 @@ public interface IReadOnlyMongoRepository where TKey : IEquatable /// An optional partition key. TDocument GetOne(Expression> filter, string partitionKey = null) where TDocument : IDocument; + /// + /// Returns a collection cursor. + /// + /// The type representing a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + IFindFluent GetCursor(FilterDefinition condition, FindOptions findOption = null, string partitionKey = null) where TDocument : IDocument; + /// /// Returns a collection cursor. /// @@ -105,6 +114,20 @@ public interface IReadOnlyMongoRepository where TKey : IEquatable #region Min / Max + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// A mongodb filter definition. + /// A property selector to order by descending. + /// A mongodb filter option. + /// An optional partitionKey. + /// An optional cancellation Token. + Task GetByMaxAsync(FilterDefinition condition, + Expression> maxValueSelector, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument; + /// /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -115,6 +138,18 @@ public interface IReadOnlyMongoRepository where TKey : IEquatable Task GetByMaxAsync(Expression> filter, Expression> orderByDescending, string partitionKey = null) where TDocument : IDocument; + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// A mongodb filter definition. + /// A property selector to order by descending. + /// A mongodb filter option. + /// An optional partitionKey. + TDocument GetByMax(FilterDefinition condition, Expression> maxValueSelector, + FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument; + /// /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -126,6 +161,20 @@ Task GetByMaxAsync(Expression> filte TDocument GetByMax(Expression> filter, Expression> orderByDescending, string partitionKey = null) where TDocument : IDocument; + /// + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partitionKey. + /// An optional cancellation Token. + Task GetByMinAsync(FilterDefinition condition, + Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument; + /// /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -136,6 +185,18 @@ TDocument GetByMax(Expression> filter, Expressi Task GetByMinAsync(Expression> filter, Expression> orderByAscending, string partitionKey = null) where TDocument : IDocument; + /// + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partitionKey. + TDocument GetByMin(FilterDefinition condition, + Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument; + /// /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -146,6 +207,21 @@ Task GetByMinAsync(Expression> filte TDocument GetByMin(Expression> filter, Expression> orderByAscending, string partitionKey = null) where TDocument : IDocument; + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the field for which you want the maximum value. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partitionKey. + /// An optional cancellation Token. + Task GetMaxValueAsync(FilterDefinition condition, + Expression> maxValueSelector, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument; + /// /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// @@ -157,6 +233,19 @@ TDocument GetByMin(Expression> filter, Expressi Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null) where TDocument : IDocument; + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partitionKey. + TValue GetMaxValue(FilterDefinition condition, + Expression> maxValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument; + /// /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// @@ -168,6 +257,21 @@ Task GetMaxValueAsync(Expression(Expression> filter, Expression> maxValueSelector, string partitionKey = null) where TDocument : IDocument; + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + Task GetMinValueAsync(FilterDefinition condition, + Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument; + /// /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// @@ -179,6 +283,19 @@ TValue GetMaxValue(Expression> filter, Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null) where TDocument : IDocument; + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partition key. + TValue GetMinValue(FilterDefinition condition, + Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument; + /// /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// @@ -246,6 +363,44 @@ decimal SumBy(Expression> filter, #region Project + /// + /// Asynchronously returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A project definition. + /// An optional partition key. + /// A mongodb filter option. + /// An optional cancellation Token. + Task ProjectOneAsync( + FilterDefinition condition, + ProjectionDefinition projection, + FindOptions findOption = null, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TProjection : class; + + /// + /// Asynchronously returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// An optional partition key. + /// A mongodb filter option. + /// An optional cancellation Token. + Task ProjectOneAsync( + FilterDefinition condition, + Expression> projection, + FindOptions findOption = null, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TProjection : class; + /// /// Asynchronously returns a projected document matching the filter condition. /// @@ -259,6 +414,34 @@ Task ProjectOneAsync(Expression where TProjection : class; + /// + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A project definition. + /// A mongodb filter option. + /// An optional partition key. + TProjection ProjectOne(FilterDefinition condition, + ProjectionDefinition projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TProjection : class; + + /// + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + TProjection ProjectOne(FilterDefinition condition, + Expression> projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TProjection : class; + /// /// Returns a projected document matching the filter condition. /// @@ -271,6 +454,44 @@ TProjection ProjectOne(Expression> where TDocument : IDocument where TProjection : class; + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A project definition. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + Task> ProjectManyAsync( + FilterDefinition condition, + ProjectionDefinition projection, + FindOptions findOption = null, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + Task> ProjectManyAsync( + FilterDefinition condition, + Expression> projection, + FindOptions findOption = null, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TProjection : class; + /// /// Asynchronously returns a list of projected documents matching the filter condition. /// @@ -283,6 +504,34 @@ Task> ProjectManyAsync(Expression where TProjection : class; + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A project definition. + /// A mongodb filter option. + /// An optional partition key. + List ProjectMany(FilterDefinition condition, + ProjectionDefinition projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + List ProjectMany(FilterDefinition condition, + Expression> projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TProjection : class; + /// /// Asynchronously returns a list of projected documents matching the filter condition. /// diff --git a/MongoDbGenericRepository/BaseMongoRepository.Delete.cs b/MongoDbGenericRepository/BaseMongoRepository.Delete.cs index e86b060..bb6ef2e 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Delete.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Delete.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; +using MongoDB.Driver; namespace MongoDbGenericRepository { @@ -31,6 +32,19 @@ Task DeleteOneAsync(TDocument document) where TDocument : IDocument where TKey : IEquatable; + /// + /// Deletes a document matching the condition of the filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + long DeleteOne(FilterDefinition condition, DeleteOptions deleteOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Deletes a document matching the condition of the LINQ expression filter. /// @@ -43,6 +57,20 @@ long DeleteOne(Expression> filter, string where TDocument : IDocument where TKey : IEquatable; + /// + /// Asynchronously deletes a document matching the condition of the filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + Task DeleteOneAsync(FilterDefinition condition, DeleteOptions deleteOption = null, + string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Asynchronously deletes a document matching the condition of the LINQ expression filter. /// @@ -54,6 +82,19 @@ long DeleteOne(Expression> filter, string Task DeleteOneAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable; + + /// + /// Asynchronously deletes the documents matching the condition of the filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + Task DeleteManyAsync(FilterDefinition condition, DeleteOptions deleteOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; /// /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. @@ -88,6 +129,19 @@ Task DeleteManyAsync(IEnumerable documents) long DeleteMany(IEnumerable documents) where TDocument : IDocument where TKey : IEquatable; + + /// + /// Deletes the documents matching the condition of the filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + long DeleteMany(FilterDefinition condition, DeleteOptions deleteOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; /// /// Deletes the documents matching the condition of the LINQ expression filter. @@ -147,6 +201,19 @@ public virtual long DeleteOne(TDocument document) where TDocument : I { return MongoDbEraser.DeleteOne(document); } + + /// + /// Deletes a document. + /// + /// The type representing a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + public virtual long DeleteOne(FilterDefinition condition, DeleteOptions deleteOption = null, string partitionKey = null) where TDocument : IDocument + { + return MongoDbEraser.DeleteOne(condition, deleteOption, partitionKey).DeletedCount; + } /// /// Deletes a document matching the condition of the LINQ expression filter. @@ -160,6 +227,20 @@ public virtual long DeleteOne(Expression> filte return MongoDbEraser.DeleteOne(filter, partitionKey); } + /// + /// Asynchronously deletes a document matching the condition of the filter definition. + /// + /// The type representing a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + public virtual async Task DeleteOneAsync(FilterDefinition condition, DeleteOptions deleteOption = null, string partitionKey = null) where TDocument : IDocument + { + var result = await MongoDbEraser.DeleteOneAsync(condition, deleteOption, partitionKey); + return result.DeletedCount; + } + /// /// Asynchronously deletes a document matching the condition of the LINQ expression filter. /// @@ -172,6 +253,20 @@ public virtual async Task DeleteOneAsync(Expression(filter, partitionKey); } + /// + /// Asynchronously deletes the documents matching the condition of the filter definition. + /// + /// The type representing a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + public virtual async Task DeleteManyAsync(FilterDefinition condition, DeleteOptions deleteOption = null, string partitionKey = null) where TDocument : IDocument + { + var result = await MongoDbEraser.DeleteManyAsync(condition, deleteOption, partitionKey); + return result.DeletedCount; + } + /// /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. /// @@ -206,6 +301,19 @@ public virtual long DeleteMany(IEnumerable documents) wher return DeleteMany(documents); } + /// + /// Deletes the documents matching the condition of the filter definition. + /// + /// The type representing a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + public long DeleteMany(FilterDefinition condition, DeleteOptions deleteOption = null, string partitionKey = null) where TDocument : IDocument + { + return MongoDbEraser.DeleteMany(condition, deleteOption, partitionKey).DeletedCount; + } + /// /// Deletes the documents matching the condition of the LINQ expression filter. /// @@ -250,6 +358,23 @@ public virtual async Task DeleteOneAsync(TDocument docume return await MongoDbEraser.DeleteOneAsync(document); } + /// + /// Deletes a document matching the condition of the filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + public virtual long DeleteOne(FilterDefinition condition, DeleteOptions deleteOption = null, + string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbEraser.DeleteOne(condition, deleteOption, partitionKey).DeletedCount; + } + /// /// Deletes a document matching the condition of the LINQ expression filter. /// @@ -265,6 +390,24 @@ public virtual long DeleteOne(Expression> return MongoDbEraser.DeleteOne(filter, partitionKey); } + /// + /// Deletes a document matching the condition of the filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + public virtual async Task DeleteOneAsync(FilterDefinition condition, + DeleteOptions deleteOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + var result = await MongoDbEraser.DeleteOneAsync(condition, deleteOption, partitionKey); + return result.DeletedCount; + } + /// /// Asynchronously deletes a document matching the condition of the LINQ expression filter. /// @@ -280,6 +423,24 @@ public virtual async Task DeleteOneAsync(Expression(filter, partitionKey); } + /// + /// Asynchronously deletes the documents matching the condition of the filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + public virtual async Task DeleteManyAsync(FilterDefinition condition, + DeleteOptions deleteOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + var result = await MongoDbEraser.DeleteManyAsync(condition, deleteOption, partitionKey); + return result.DeletedCount; + } + /// /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. /// @@ -323,6 +484,20 @@ public virtual long DeleteMany(IEnumerable documents return MongoDbEraser.DeleteMany(documents); } + /// + /// Deletes the documents matching the condition of the filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + public virtual long DeleteMany(FilterDefinition condition, DeleteOptions deleteOption = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable + { + return MongoDbEraser.DeleteMany(condition, deleteOption, partitionKey).DeletedCount; + } + /// /// Deletes the documents matching the condition of the LINQ expression filter. /// diff --git a/MongoDbGenericRepository/BaseMongoRepository.Main.cs b/MongoDbGenericRepository/BaseMongoRepository.Main.cs index 09664e8..8498a83 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Main.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Main.cs @@ -24,7 +24,7 @@ protected BaseMongoRepository(string connectionString, string databaseName = nul } /// - /// The contructor taking a . + /// The constructor taking a . /// /// A mongodb context implementing protected BaseMongoRepository(IMongoDbContext mongoDbContext) : base(mongoDbContext) @@ -32,13 +32,28 @@ protected BaseMongoRepository(IMongoDbContext mongoDbContext) : base(mongoDbCont } /// - /// The contructor taking a . + /// The constructor taking a . /// /// A mongodb context implementing protected BaseMongoRepository(IMongoDatabase mongoDatabase) : base(mongoDatabase) { } + /// + /// Asynchronously returns a paginated list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// The number of documents you want to skip. Default value is 0. + /// The number of documents you want to take. Default value is 50. + /// An optional partition key. + public virtual Task> GetPaginatedAsync(FilterDefinition condition, FindOptions findOption = null, int skipNumber = 0, int takeNumber = 50, + string partitionKey = null) where TDocument : IDocument + { + return HandlePartitioned(partitionKey).Find(condition, findOption).Skip(skipNumber).Limit(takeNumber).ToListAsync(); + } + /// /// Asynchronously returns a paginated list of the documents matching the filter condition. /// @@ -57,6 +72,22 @@ public virtual async Task> GetPaginatedAsync( return await HandlePartitioned(partitionKey).Find(filter).Skip(skipNumber).Limit(takeNumber).ToListAsync(); } + /// + /// Asynchronously returns a paginated list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// The number of documents you want to skip. Default value is 0. + /// The number of documents you want to take. Default value is 50. + /// An optional partition key. + public virtual Task> GetPaginatedAsync(FilterDefinition condition, FindOptions findOption = null, int skipNumber = 0, int takeNumber = 50, + string partitionKey = null) where TDocument : IDocument where TKey : IEquatable + { + return HandlePartitioned(partitionKey).Find(condition, findOption).Skip(skipNumber).Limit(takeNumber).ToListAsync(); + } + /// /// Asynchronously returns a paginated list of the documents matching the filter condition. /// diff --git a/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs b/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs index eded8d5..d588166 100644 --- a/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs +++ b/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs @@ -132,6 +132,24 @@ protected virtual CreateIndexOptions MapIndexOptions(IndexCreationOptions indexC }; } + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partition key. + protected virtual IFindFluent GetMinMongoQuery(FilterDefinition condition, Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return GetCollection(partitionKey).Find(condition, findOption) + .SortBy(ConvertExpression(minValueSelector)) + .Limit(1); + } /// /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. @@ -151,6 +169,25 @@ protected virtual IFindFluent GetMinMongoQuery + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by descending. + /// A mongodb filter option. + /// An optional partition key. + protected virtual IFindFluent GetMaxMongoQuery(FilterDefinition condition, Expression> maxValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return GetCollection(partitionKey).Find(condition, findOption) + .SortByDescending(ConvertExpression(maxValueSelector)) + .Limit(1); + } + /// /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// diff --git a/MongoDbGenericRepository/DataAccess/Delete/MongoDbEraser.cs b/MongoDbGenericRepository/DataAccess/Delete/MongoDbEraser.cs index 1daabac..29108d9 100644 --- a/MongoDbGenericRepository/DataAccess/Delete/MongoDbEraser.cs +++ b/MongoDbGenericRepository/DataAccess/Delete/MongoDbEraser.cs @@ -48,6 +48,23 @@ public virtual async Task DeleteOneAsync(TDocument docume return (await HandlePartitioned(document).DeleteOneAsync(filter)).DeletedCount; } + /// + /// Deletes a document matching the condition of the filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + /// The number of documents deleted. + public virtual DeleteResult DeleteOne(FilterDefinition condition, DeleteOptions deleteOption = null, + string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return HandlePartitioned(partitionKey).DeleteOne(condition, deleteOption); + } + /// /// Deletes a document matching the condition of the LINQ expression filter. /// @@ -63,6 +80,22 @@ public virtual long DeleteOne(Expression> return HandlePartitioned(partitionKey).DeleteOne(filter).DeletedCount; } + /// + /// Asynchronously deletes a document matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + /// The number of documents deleted. + public virtual Task DeleteOneAsync(FilterDefinition condition, DeleteOptions deleteOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return HandlePartitioned(partitionKey).DeleteOneAsync(condition, deleteOption); + } + /// /// Asynchronously deletes a document matching the condition of the LINQ expression filter. /// @@ -78,6 +111,23 @@ public virtual async Task DeleteOneAsync(Expression(partitionKey).DeleteOneAsync(filter)).DeletedCount; } + /// + /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + /// The number of documents deleted. + public virtual Task DeleteManyAsync(FilterDefinition condition, + DeleteOptions deleteOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return HandlePartitioned(partitionKey).DeleteManyAsync(condition, deleteOption); + } + /// /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. /// @@ -159,6 +209,23 @@ public virtual long DeleteMany(IEnumerable documents } } + /// + /// Deletes the documents matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + /// The number of documents deleted. + public virtual DeleteResult DeleteMany(FilterDefinition condition, DeleteOptions deleteOption = null, + string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return HandlePartitioned(partitionKey).DeleteMany(condition, deleteOption); + } + /// /// Deletes the documents matching the condition of the LINQ expression filter. /// diff --git a/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Main.cs b/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Main.cs index c343668..adde753 100644 --- a/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Main.cs +++ b/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Main.cs @@ -119,6 +119,22 @@ public virtual TDocument GetOne(Expression(partitionKey).Find(filter).FirstOrDefault(); } + /// + /// Returns a collection cursor. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + public virtual IFindFluent GetCursor(FilterDefinition condition, FindOptions findOption = null, + string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return HandlePartitioned(partitionKey).Find(condition, findOption); + } + /// /// Returns a collection cursor. /// @@ -327,6 +343,28 @@ public virtual long Count(Expression> fil #region Min / Max + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// A mongodb filter definition. + /// A property selector to order by descending. + /// A mongodb filter option. + /// An optional partitionKey. + /// An optional cancellation Token. + public virtual Task GetByMaxAsync(FilterDefinition condition, + Expression> maxValueSelector, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + { + return GetCollection(partitionKey).Find(condition, findOption) + .SortByDescending(maxValueSelector) + .Limit(1) + .FirstOrDefaultAsync(cancellationToken); + } + /// /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -345,6 +383,25 @@ public async virtual Task GetByMaxAsync(Expression + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// A mongodb filter definition. + /// A property selector to order by descending. + /// A mongodb filter option. + /// An optional partitionKey. + public virtual TDocument GetByMax(FilterDefinition condition, Expression> maxValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return GetCollection(partitionKey).Find(condition, findOption) + .SortByDescending(maxValueSelector) + .Limit(1) + .FirstOrDefault(); + } /// /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. @@ -364,6 +421,28 @@ public virtual TDocument GetByMax(Expression + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partitionKey. + /// An optional cancellation Token. + public virtual Task GetByMinAsync(FilterDefinition condition, + Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + { + return GetCollection(partitionKey).Find(condition, findOption) + .SortBy(minValueSelector) + .Limit(1) + .FirstOrDefaultAsync(cancellationToken); + } + /// /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -383,6 +462,26 @@ public async virtual Task GetByMinAsync(Expression + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partitionKey. + public virtual TDocument GetByMin(FilterDefinition condition, + Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return GetCollection(partitionKey).Find(condition, findOption) + .SortBy(minValueSelector) + .Limit(1) + .FirstOrDefault(); + } + /// /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -401,6 +500,28 @@ public virtual TDocument GetByMin(Expression + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the field for which you want the maximum value. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partitionKey. + /// An optional cancellation Token. + public virtual Task GetMaxValueAsync(FilterDefinition condition, + Expression> maxValueSelector, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + { + return GetMaxMongoQuery(condition, maxValueSelector, findOption, partitionKey) + .Project(maxValueSelector) + .FirstOrDefaultAsync(cancellationToken); + } + /// /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// @@ -420,6 +541,25 @@ public async virtual Task GetMaxValueAsync(Expr .FirstOrDefaultAsync(cancellationToken); } + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partitionKey. + public virtual TValue GetMaxValue(FilterDefinition condition, Expression> maxValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return GetMaxMongoQuery(condition, maxValueSelector, findOption, partitionKey) + .Project(maxValueSelector) + .FirstOrDefault(); + } + /// /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// @@ -438,6 +578,27 @@ public virtual TValue GetMaxValue(Expression + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + public virtual Task GetMinValueAsync(FilterDefinition condition, + Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + { + return GetMinMongoQuery(condition, minValueSelector, findOption, partitionKey) + .Project(minValueSelector).FirstOrDefaultAsync(cancellationToken); + } + /// /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// @@ -455,6 +616,25 @@ public virtual async Task GetMinValueAsync(Expr return await GetMinMongoQuery(filter, minValueSelector, partitionKey).Project(minValueSelector).FirstOrDefaultAsync(cancellationToken); } + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partition key. + public virtual TValue GetMinValue(FilterDefinition condition, + Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return GetMinMongoQuery(condition, minValueSelector, findOption, partitionKey) + .Project(minValueSelector).FirstOrDefault(); + } + /// /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// diff --git a/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Project.cs b/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Project.cs index 378e86e..23c32cf 100644 --- a/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Project.cs +++ b/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Project.cs @@ -12,6 +12,58 @@ namespace MongoDbGenericRepository.DataAccess.Read { public partial class MongoDbReader { + /// + /// Asynchronously returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A project definition. + /// An optional partition key. + /// A mongodb filter option. + /// An optional cancellation Token. + public virtual Task ProjectOneAsync( + FilterDefinition condition, + ProjectionDefinition projection, + FindOptions findOption = null, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return HandlePartitioned(partitionKey).Find(condition, findOption) + .Project(projection) + .FirstOrDefaultAsync(cancellationToken); + } + + /// + /// Asynchronously returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// An optional partition key. + /// A mongodb filter option. + /// An optional cancellation Token. + public virtual Task ProjectOneAsync( + FilterDefinition condition, + Expression> projection, + FindOptions findOption = null, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return HandlePartitioned(partitionKey).Find(condition, findOption) + .Project(projection) + .FirstOrDefaultAsync(cancellationToken); + } + /// /// Asynchronously returns a projected document matching the filter condition. /// @@ -36,6 +88,48 @@ public virtual async Task ProjectOneAsync + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A project definition. + /// A mongodb filter option. + /// An optional partition key. + public virtual TProjection ProjectOne(FilterDefinition condition, + ProjectionDefinition projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return HandlePartitioned(partitionKey).Find(condition, findOption) + .Project(projection) + .FirstOrDefault(); + } + + /// + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + public virtual TProjection ProjectOne(FilterDefinition condition, + Expression> projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return HandlePartitioned(partitionKey).Find(condition, findOption) + .Project(projection) + .FirstOrDefault(); + } + /// /// Returns a projected document matching the filter condition. /// @@ -55,6 +149,58 @@ public virtual TProjection ProjectOne(Expression + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A project definition. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + public virtual Task> ProjectManyAsync( + FilterDefinition condition, + ProjectionDefinition projection, + FindOptions findOption = null, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return HandlePartitioned(partitionKey).Find(condition, findOption) + .Project(projection) + .ToListAsync(cancellationToken); + } + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + public virtual Task> ProjectManyAsync( + FilterDefinition condition, + Expression> projection, + FindOptions findOption = null, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return HandlePartitioned(partitionKey).Find(condition, findOption) + .Project(projection) + .ToListAsync(cancellationToken); + } + /// /// Asynchronously returns a list of projected documents matching the filter condition. /// @@ -79,6 +225,48 @@ public virtual async Task> ProjectManyAsync + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A project definition. + /// A mongodb filter option. + /// An optional partition key. + public virtual List ProjectMany(FilterDefinition condition, + ProjectionDefinition projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return HandlePartitioned(partitionKey).Find(condition, findOption) + .Project(projection) + .ToList(); + } + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + public virtual List ProjectMany(FilterDefinition condition, + Expression> projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return HandlePartitioned(partitionKey).Find(condition, findOption) + .Project(projection) + .ToList(); + } + /// /// Asynchronously returns a list of projected documents matching the filter condition. /// diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Delete.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Delete.cs index 7324b2e..e71b65d 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Delete.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Delete.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; +using MongoDB.Driver; namespace MongoDbGenericRepository { @@ -31,6 +32,17 @@ long DeleteOne(TDocument document) Task DeleteOneAsync(TDocument document) where TDocument : IDocument; + /// + /// Deletes a document matching the condition of the filter definition. + /// + /// The type representing a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + long DeleteOne(FilterDefinition condition, DeleteOptions deleteOption = null, string partitionKey = null) + where TDocument : IDocument; + /// /// Deletes a document matching the condition of the LINQ expression filter. /// @@ -40,6 +52,17 @@ Task DeleteOneAsync(TDocument document) /// The number of documents deleted. long DeleteOne(Expression> filter, string partitionKey = null) where TDocument : IDocument; + + /// + /// Asynchronously deletes a document matching the condition of the filter definition. + /// + /// The type representing a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + Task DeleteOneAsync(FilterDefinition condition, DeleteOptions deleteOption = null, string partitionKey = null) + where TDocument : IDocument; /// /// Asynchronously deletes a document matching the condition of the LINQ expression filter. @@ -51,6 +74,17 @@ long DeleteOne(Expression> filter, string parti Task DeleteOneAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; + /// + /// Asynchronously deletes the documents matching the condition of the filter definition. + /// + /// The type representing a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + Task DeleteManyAsync(FilterDefinition condition, DeleteOptions deleteOption = null, string partitionKey = null) + where TDocument : IDocument; + /// /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. /// @@ -79,6 +113,18 @@ Task DeleteManyAsync(IEnumerable documents) long DeleteMany(IEnumerable documents) where TDocument : IDocument; + /// + /// Deletes the documents matching the condition of the filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + long DeleteMany(FilterDefinition condition, DeleteOptions deleteOption = null, string partitionKey = null) + where TDocument : IDocument; + /// /// Deletes the documents matching the condition of the LINQ expression filter. /// @@ -140,6 +186,20 @@ public virtual async Task DeleteOneAsync(TDocument document) return await MongoDbEraser.DeleteOneAsync(document); } + /// + /// Deletes a document matching the condition of the filter definition. + /// + /// The type representing a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + public virtual long DeleteOne(FilterDefinition condition, DeleteOptions deleteOption = null, + string partitionKey = null) where TDocument : IDocument + { + return MongoDbEraser.DeleteOne(condition, deleteOption, partitionKey).DeletedCount; + } + /// /// Deletes a document matching the condition of the LINQ expression filter. /// @@ -153,6 +213,20 @@ public virtual long DeleteOne(Expression> filte return MongoDbEraser.DeleteOne(filter, partitionKey); } + /// + /// Deletes a document matching the condition of the filter definition. + /// + /// The type representing a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + public virtual async Task DeleteOneAsync(FilterDefinition condition, DeleteOptions deleteOption = null, string partitionKey = null) where TDocument : IDocument + { + var result = await MongoDbEraser.DeleteOneAsync(condition, deleteOption, partitionKey); + return result.DeletedCount; + } + /// /// Asynchronously deletes a document matching the condition of the LINQ expression filter. /// @@ -166,6 +240,21 @@ public virtual async Task DeleteOneAsync(Expression(filter, partitionKey); } + /// + /// Asynchronously deletes the documents matching the condition of the filter definition. + /// + /// The type representing a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + public virtual async Task DeleteManyAsync(FilterDefinition condition, DeleteOptions deleteOption = null, + string partitionKey = null) where TDocument : IDocument + { + var result = await MongoDbEraser.DeleteManyAsync(condition, deleteOption, partitionKey); + return result.DeletedCount; + } + /// /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. /// @@ -203,6 +292,19 @@ public virtual long DeleteMany(IEnumerable documents) return MongoDbEraser.DeleteMany(documents); } + /// + /// Deletes the documents matching the condition of the filter definition. + /// + /// The type representing a Document. + /// A mongodb filter definition. + /// A mongodb delete option. + /// An optional partition key. + /// The number of documents deleted. + public long DeleteMany(FilterDefinition condition, DeleteOptions deleteOption = null, string partitionKey = null) where TDocument : IDocument + { + return MongoDbEraser.DeleteMany(condition, deleteOption, partitionKey).DeletedCount; + } + /// /// Deletes the documents matching the condition of the LINQ expression filter. /// diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.ReadOnly.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.ReadOnly.cs index cdbb862..7f1c865 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.ReadOnly.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.ReadOnly.cs @@ -127,6 +127,18 @@ public TDocument GetOne(Expression> filter, str return MongoDbReader.GetOne(filter, partitionKey); } + /// + /// Returns a collection cursor. + /// + /// The type representing a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + public IFindFluent GetCursor(FilterDefinition condition, FindOptions findOption = null, string partitionKey = null) where TDocument : IDocument + { + return MongoDbReader.GetCursor(condition, findOption, partitionKey); + } + /// /// Returns a collection cursor. /// @@ -204,6 +216,23 @@ public long Count(Expression> filter, string pa return MongoDbReader.Count(filter, partitionKey); } + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// A mongodb filter definition. + /// A property selector to order by descending. + /// A mongodb filter option. + /// An optional partitionKey. + /// An optional cancellation Token. + public virtual Task GetByMaxAsync(FilterDefinition condition, + Expression> maxValueSelector, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + { + return MongoDbReader.GetByMaxAsync(condition, maxValueSelector, findOption, partitionKey, cancellationToken); + } + /// /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -217,6 +246,21 @@ public async Task GetByMaxAsync(Expression(filter, maxValueSelector, partitionKey); } + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// A mongodb filter definition. + /// A property selector to order by descending. + /// A mongodb filter option. + /// An optional partitionKey. + public virtual TDocument GetByMax(FilterDefinition condition, Expression> maxValueSelector, + FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + { + return MongoDbReader.GetByMax(condition, maxValueSelector, findOption, partitionKey); + } + /// /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -231,6 +275,23 @@ public TDocument GetByMax(Expression> filter, E return MongoDbReader.GetByMax(filter, maxValueSelector, partitionKey); } + /// + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partitionKey. + /// An optional cancellation Token. + public virtual Task GetByMinAsync(FilterDefinition condition, + Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + { + return MongoDbReader.GetByMinAsync(condition, minValueSelector, findOption, partitionKey, cancellationToken); + } + /// /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -244,6 +305,20 @@ public async Task GetByMinAsync(Expression(filter, minValueSelector, partitionKey); } + /// + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partitionKey. + public virtual TDocument GetByMin(FilterDefinition condition, Expression> minValueSelector, + FindOptions findOption = null, string partitionKey = null) where TDocument : IDocument + { + return MongoDbReader.GetByMin(condition, minValueSelector, findOption, partitionKey); + } + /// /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -257,6 +332,24 @@ public TDocument GetByMin(Expression> filter, E return MongoDbReader.GetByMin(filter, minValueSelector, partitionKey); } + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the field for which you want the maximum value. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partitionKey. + /// An optional cancellation Token. + public virtual Task GetMaxValueAsync(FilterDefinition condition, + Expression> maxValueSelector, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + { + return MongoDbReader.GetMaxValueAsync(condition, maxValueSelector, findOption, partitionKey, cancellationToken); + } + /// /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// @@ -271,6 +364,22 @@ public async Task GetMaxValueAsync(Expression(filter, maxValueSelector, partitionKey); } + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partitionKey. + public virtual TValue GetMaxValue(FilterDefinition condition, + Expression> maxValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + { + return MongoDbReader.GetMaxValue(condition, maxValueSelector, findOption, partitionKey); + } + /// /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// @@ -285,6 +394,25 @@ public TValue GetMaxValue(Expression> f return MongoDbReader.GetMaxValue(filter, maxValueSelector, partitionKey); } + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + public virtual Task GetMinValueAsync(FilterDefinition condition, + Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + { + return MongoDbReader.GetMinValueAsync(condition, minValueSelector, findOption, partitionKey, cancellationToken); + } + /// /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// @@ -299,6 +427,22 @@ public virtual async Task GetMinValueAsync(Expression return await MongoDbReader.GetMinValueAsync(filter, minValueSelector, partitionKey); } + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partition key. + public virtual TValue GetMinValue(FilterDefinition condition, + Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + { + return MongoDbReader.GetMinValue(condition, minValueSelector, findOption, partitionKey); + } + /// /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// @@ -381,6 +525,44 @@ public virtual decimal SumBy(Expression> filter #region Project + /// + /// Asynchronously returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A project definition. + /// An optional partition key. + /// A mongodb filter option. + /// An optional cancellation Token. + public virtual Task ProjectOneAsync(FilterDefinition condition, + ProjectionDefinition projection, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TProjection : class + { + return MongoDbReader.ProjectOneAsync(condition, projection, findOption, partitionKey, cancellationToken); + } + + /// + /// Asynchronously returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// An optional partition key. + /// A mongodb filter option. + /// An optional cancellation Token. + public virtual Task ProjectOneAsync(FilterDefinition condition, + Expression> projection, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TProjection : class + { + return MongoDbReader.ProjectOneAsync(condition, projection, findOption, partitionKey, cancellationToken); + } + /// /// Asynchronously returns a projected document matching the filter condition. /// @@ -397,6 +579,40 @@ public virtual async Task ProjectOneAsync(E return await MongoDbReader.ProjectOneAsync(filter, projection, partitionKey); } + /// + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A project definition. + /// A mongodb filter option. + /// An optional partition key. + public virtual TProjection ProjectOne(FilterDefinition condition, + ProjectionDefinition projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TProjection : class + { + return MongoDbReader.ProjectOne(condition, projection, findOption, partitionKey); + } + + /// + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + public virtual TProjection ProjectOne(FilterDefinition condition, + Expression> projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TProjection : class + { + return MongoDbReader.ProjectOne(condition, projection, findOption, partitionKey); + } + /// /// Returns a projected document matching the filter condition. /// @@ -412,6 +628,44 @@ public virtual TProjection ProjectOne(Expression(filter, projection, partitionKey); } + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A project definition. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + public virtual Task> ProjectManyAsync(FilterDefinition condition, + ProjectionDefinition projection, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TProjection : class + { + return MongoDbReader.ProjectManyAsync(condition, projection, findOption, partitionKey, cancellationToken); + } + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + public virtual Task> ProjectManyAsync(FilterDefinition condition, + Expression> projection, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TProjection : class + { + return MongoDbReader.ProjectManyAsync(condition, projection, findOption, partitionKey, cancellationToken); + } + /// /// Asynchronously returns a list of projected documents matching the filter condition. /// @@ -427,6 +681,40 @@ public virtual async Task> ProjectManyAsync(filter, projection, partitionKey); } + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A project definition. + /// A mongodb filter option. + /// An optional partition key. + public List ProjectMany(FilterDefinition condition, + ProjectionDefinition projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TProjection : class + { + return MongoDbReader.ProjectMany(condition, projection, findOption, partitionKey); + } + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + public List ProjectMany(FilterDefinition condition, + Expression> projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TProjection : class + { + return MongoDbReader.ProjectMany(condition, projection, findOption, partitionKey); + } + /// /// Asynchronously returns a list of projected documents matching the filter condition. /// diff --git a/MongoDbGenericRepository/ReadOnlyMongoRepository.cs b/MongoDbGenericRepository/ReadOnlyMongoRepository.cs index 1959003..39dbda4 100644 --- a/MongoDbGenericRepository/ReadOnlyMongoRepository.cs +++ b/MongoDbGenericRepository/ReadOnlyMongoRepository.cs @@ -130,6 +130,19 @@ public virtual TDocument GetOne(Expression(filter, partitionKey); } + /// + /// Returns a collection cursor. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + public virtual IFindFluent GetCursor(FilterDefinition condition, FindOptions findOption = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable + { + return MongoDbReader.GetCursor(condition, findOption, partitionKey); + } + /// /// Returns a collection cursor. /// @@ -317,6 +330,22 @@ public virtual long Count(Expression> fil return MongoDbReader.Count(filter, partitionKey); } + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// A mongodb filter definition. + /// A property selector to order by descending. + /// A mongodb filter option. + /// An optional partitionKey. + /// An optional cancellation Token. + public virtual Task GetByMaxAsync(FilterDefinition condition, Expression> maxValueSelector, FindOptions findOption = null, + string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable + { + return MongoDbReader.GetByMaxAsync(condition, maxValueSelector, findOption, partitionKey, cancellationToken); + } + /// /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -336,6 +365,22 @@ public async virtual Task GetByMaxAsync( return await MongoDbReader.GetByMaxAsync(filter, maxValueSelector, partitionKey, cancellationToken); } + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// A mongodb filter definition. + /// A property selector to order by descending. + /// A mongodb filter option. + /// An optional partitionKey. + public virtual TDocument GetByMax(FilterDefinition condition, + Expression> maxValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument where TKey : IEquatable + { + return MongoDbReader.GetByMax(condition, maxValueSelector, findOption, partitionKey); + } + /// /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -351,6 +396,23 @@ public virtual TDocument GetByMax(Expression(filter, maxValueSelector, partitionKey); } + /// + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// A mongodb filter definition. + /// A property selector for the minimum value you are looking for. + /// A mongodb filter option. + /// An optional partitionKey. + /// An optional cancellation Token. + public virtual Task GetByMinAsync(FilterDefinition condition, + Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable + { + return MongoDbReader.GetByMinAsync(condition, minValueSelector, findOption, partitionKey, cancellationToken); + } + /// /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -370,6 +432,22 @@ public async virtual Task GetByMinAsync(Expression(filter, minValueSelector, partitionKey, cancellationToken); } + /// + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// A mongodb filter definition. + /// A property selector for the minimum value you are looking for. + /// A mongodb filter option. + /// An optional partitionKey. + public virtual TDocument GetByMin(FilterDefinition condition, + Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument where TKey : IEquatable + { + return MongoDbReader.GetByMin(condition, minValueSelector, findOption, partitionKey); + } + /// /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. /// @@ -385,6 +463,13 @@ public virtual TDocument GetByMin(Expression(filter, minValueSelector, partitionKey); } + public virtual Task GetMaxValueAsync(FilterDefinition condition, + Expression> maxValueSelector, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable + { + return MongoDbReader.GetMaxValueAsync(condition, maxValueSelector, findOption, partitionKey, cancellationToken); + } + /// /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// @@ -406,6 +491,23 @@ public async virtual Task GetMaxValueAsync( return await MongoDbReader.GetMaxValueAsync(filter, maxValueSelector, partitionKey, cancellationToken); } + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partitionKey. + public virtual TValue GetMaxValue(FilterDefinition condition, + Expression> maxValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument where TKey : IEquatable + { + return MongoDbReader.GetMaxValue(condition, maxValueSelector, findOption, partitionKey); + } + /// /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// @@ -422,6 +524,24 @@ public virtual TValue GetMaxValue(Expression(filter, maxValueSelector, partitionKey); } + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + public virtual Task GetMinValueAsync(FilterDefinition condition, + Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable + { + return MongoDbReader.GetMinValueAsync(condition, minValueSelector, findOption, partitionKey, cancellationToken); + } + /// /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// @@ -443,6 +563,23 @@ public virtual async Task GetMinValueAsync( return await MongoDbReader.GetMinValueAsync(filter, minValueSelector, partitionKey, cancellationToken); } + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// The type of the value used to order the query. + /// A mongodb filter definition. + /// A property selector to order by ascending. + /// A mongodb filter option. + /// An optional partition key. + public TValue GetMinValue(FilterDefinition condition, + Expression> minValueSelector, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument where TKey : IEquatable + { + return MongoDbReader.GetMinValue(condition, minValueSelector, findOption, partitionKey); + } + /// /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// @@ -537,6 +674,48 @@ public virtual decimal SumBy(Expression> #region Project TKey + /// + /// Asynchronously returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A projection definition. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + public virtual Task ProjectOneAsync(FilterDefinition condition, + ProjectionDefinition projection, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TProjection : class + where TKey : IEquatable + { + return MongoDbReader.ProjectOneAsync(condition, projection, findOption, partitionKey, cancellationToken); + } + + /// + /// Asynchronously returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + public virtual Task ProjectOneAsync(FilterDefinition condition, + Expression> projection, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TProjection : class + where TKey : IEquatable + { + return MongoDbReader.ProjectOneAsync(condition, projection, findOption, partitionKey, cancellationToken); + } + /// /// Asynchronously returns a projected document matching the filter condition. /// @@ -559,6 +738,44 @@ public virtual async Task ProjectOneAsync(filter, projection, partitionKey, cancellationToken); } + /// + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A projection definition. + /// A mongodb filter option. + /// An optional partition key. + public virtual TProjection ProjectOne(FilterDefinition condition, + ProjectionDefinition projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TProjection : class + where TKey : IEquatable + { + return MongoDbReader.ProjectOne(condition, projection, findOption, partitionKey); + } + + /// + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + public virtual TProjection ProjectOne(FilterDefinition condition, + Expression> projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TProjection : class + where TKey : IEquatable + { + return MongoDbReader.ProjectOne(condition, projection, findOption, partitionKey); + } + /// /// Returns a projected document matching the filter condition. /// @@ -576,6 +793,48 @@ public virtual TProjection ProjectOne(Expression(filter, projection, partitionKey); } + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A projection definition. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + public virtual Task> ProjectManyAsync(FilterDefinition condition, + ProjectionDefinition projection, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TProjection : class + where TKey : IEquatable + { + return MongoDbReader.ProjectManyAsync(condition, projection, findOption, partitionKey, cancellationToken); + } + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + public virtual Task> ProjectManyAsync(FilterDefinition condition, + Expression> projection, FindOptions findOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TProjection : class + where TKey : IEquatable + { + return MongoDbReader.ProjectManyAsync(condition, projection, findOption, partitionKey, cancellationToken); + } + /// /// Asynchronously returns a list of projected documents matching the filter condition. /// @@ -597,6 +856,41 @@ public virtual async Task> ProjectManyAsync(filter, projection, partitionKey, cancellationToken); } + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// A projection definition. + /// A mongodb filter option. + /// An optional partition key. + public virtual List ProjectMany(FilterDefinition condition, + ProjectionDefinition projection, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TProjection : class + where TKey : IEquatable + { + return MongoDbReader.ProjectMany(condition, projection, findOption, partitionKey); + } + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// A mongodb filter definition. + /// The projection expression. + /// A mongodb filter option. + /// An optional partition key. + public virtual List ProjectMany(FilterDefinition condition, Expression> projection, FindOptions findOption = null, + string partitionKey = null) where TDocument : IDocument where TProjection : class where TKey : IEquatable + { + return MongoDbReader.ProjectMany(condition, projection, findOption, partitionKey); + } + /// /// Asynchronously returns a list of projected documents matching the filter condition. /// @@ -666,9 +960,36 @@ public virtual List GroupBy + /// Asynchronously returns a paginated list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// The property selector. + /// A mongodb filter option. + /// Order of the sorting. + /// The number of documents you want to skip. Default value is 0. + /// The number of documents you want to take. Default value is 50. + /// An optional partition key. + public virtual Task> GetSortedPaginatedAsync(FilterDefinition condition, + Expression> sortSelector, FindOptions findOption = null, bool ascending = true, int skipNumber = 0, + int takeNumber = 50, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable + { + var sorting = ascending + ? Builders.Sort.Ascending(sortSelector) + : Builders.Sort.Descending(sortSelector); + + return HandlePartitioned(partitionKey) + .Find(condition, findOption) + .Sort(sorting) + .Skip(skipNumber) + .Limit(takeNumber) + .ToListAsync(); + } + /// /// Asynchronously returns a paginated list of the documents matching the filter condition. /// @@ -702,6 +1023,29 @@ public virtual async Task> GetSortedPaginatedAsync + /// Asynchronously returns a paginated list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// The sort definition. + /// A mongodb filter option. + /// The number of documents you want to skip. Default value is 0. + /// The number of documents you want to take. Default value is 50. + /// An optional partition key. + /// An optional cancellation Token. + public virtual Task> GetSortedPaginatedAsync(FilterDefinition condition, SortDefinition sortDefinition, FindOptions findOption = null, + int skipNumber = 0, int takeNumber = 50, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable + { + return HandlePartitioned(partitionKey) + .Find(condition, findOption) + .Sort(sortDefinition) + .Skip(skipNumber) + .Limit(takeNumber) + .ToListAsync(cancellationToken); + } + /// /// Asynchronously returns a paginated list of the documents matching the filter condition. /// @@ -733,8 +1077,6 @@ public virtual async Task> GetSortedPaginatedAsync /// Gets a collections for a potentially partitioned document type. ///