diff --git a/CoreIntegrationTests/CoreIntegrationTests.csproj b/CoreIntegrationTests/CoreIntegrationTests.csproj index 2e4ad1b..4edac06 100644 --- a/CoreIntegrationTests/CoreIntegrationTests.csproj +++ b/CoreIntegrationTests/CoreIntegrationTests.csproj @@ -7,13 +7,16 @@ - + + + + Always diff --git a/IntegrationTests/App.config b/IntegrationTests/App.config index 139995c..6d19a67 100644 --- a/IntegrationTests/App.config +++ b/IntegrationTests/App.config @@ -7,4 +7,12 @@ + + + + + + + + \ No newline at end of file diff --git a/IntegrationTests/CreateTKeyPartitionedTests.cs b/IntegrationTests/CreateTKeyPartitionedTests.cs new file mode 100644 index 0000000..4d00dd5 --- /dev/null +++ b/IntegrationTests/CreateTKeyPartitionedTests.cs @@ -0,0 +1,76 @@ +using IntegrationTests.Infrastructure; +using MongoDB.Bson.Serialization.Attributes; +using MongoDbGenericRepository.Models; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace IntegrationTests +{ + public class CreateTestsPartitionedTKeyDocument : IDocument, IPartitionedDocument + { + [BsonId] + public Guid Id { get; set; } + public int Version { get; set; } + public CreateTestsPartitionedTKeyDocument() + { + Id = Guid.NewGuid(); + Version = 2; + PartitionKey = "TestPartitionKey"; + } + public string PartitionKey { get; set; } + public string SomeContent { get; set; } + } + + public class CreatePartitionedTKeyTests : BaseMongoDbRepositoryTests + { + [Test] + public void PartitionedAddOne() + { + // Arrange + var document = new CreateTestsPartitionedTKeyDocument(); + // Act + SUT.AddOne(document); + // Assert + long count = SUT.Count(e => e.Id == document.Id, PartitionKey); + Assert.AreEqual(1, count); + } + + [Test] + public async Task PartitionedAddOneAsync() + { + // Arrange + var document = new CreateTestsPartitionedTKeyDocument(); + // Act + await SUT.AddOneAsync(document); + // Assert + long count = SUT.Count(e => e.Id == document.Id, PartitionKey); + Assert.AreEqual(1, count); + } + + [Test] + public void PartitionedAddMany() + { + // Arrange + var documents = new List { new CreateTestsPartitionedTKeyDocument(), new CreateTestsPartitionedTKeyDocument() }; + // Act + SUT.AddMany(documents); + // Assert + long count = SUT.Count(e => e.Id == documents[0].Id || e.Id == documents[1].Id, PartitionKey); + Assert.AreEqual(2, count); + } + + [Test] + public async Task PartitionedAddManyAsync() + { + // Arrange + var documents = new List { new CreateTestsPartitionedTKeyDocument(), new CreateTestsPartitionedTKeyDocument() }; + // Act + await SUT.AddManyAsync(documents); + // Assert + long count = SUT.Count(e => e.Id == documents[0].Id || e.Id == documents[1].Id, PartitionKey); + Assert.AreEqual(2, count); + } + } +} diff --git a/IntegrationTests/CreateTKeyTests.cs b/IntegrationTests/CreateTKeyTests.cs new file mode 100644 index 0000000..f709ba7 --- /dev/null +++ b/IntegrationTests/CreateTKeyTests.cs @@ -0,0 +1,75 @@ +using IntegrationTests.Infrastructure; +using MongoDB.Bson.Serialization.Attributes; +using MongoDbGenericRepository.Models; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace IntegrationTests +{ + public class CreateTestsTKeyDocument : IDocument + { + [BsonId] + public Guid Id { get; set; } + public int Version { get; set; } + public CreateTestsTKeyDocument() + { + Id = Guid.NewGuid(); + Version = 2; + } + public string SomeContent { get; set; } + } + + [TestFixture] + public class CreateTKeyTests : BaseMongoDbRepositoryTests + { + [Test] + public void TKeyAddOne() + { + // Arrange + var document = new CreateTestsTKeyDocument(); + // Act + SUT.AddOne(document); + // Assert + long count = SUT.Count(e => e.Id == document.Id); + Assert.AreEqual(1, count); + } + + [Test] + public async Task TKeyAddOneAsync() + { + // Arrange + var document = new CreateTestsTKeyDocument(); + // Act + await SUT.AddOneAsync(document); + // Assert + long count = SUT.Count(e => e.Id == document.Id); + Assert.AreEqual(1, count); + } + + [Test] + public void TKeyAddMany() + { + // Arrange + var documents = new List { new CreateTestsTKeyDocument(), new CreateTestsTKeyDocument() }; + // Act + SUT.AddMany(documents); + // Assert + long count = SUT.Count(e => e.Id == documents[0].Id || e.Id == documents[1].Id); + Assert.AreEqual(2, count); + } + + [Test] + public async Task TKeyAddManyAsync() + { + // Arrange + var documents = new List { new CreateTestsTKeyDocument(), new CreateTestsTKeyDocument() }; + // Act + await SUT.AddManyAsync(documents); + // Assert + long count = SUT.Count(e => e.Id == documents[0].Id || e.Id == documents[1].Id); + Assert.AreEqual(2, count); + } + } +} diff --git a/IntegrationTests/DeletePartitionedTKeyTests.cs b/IntegrationTests/DeletePartitionedTKeyTests.cs new file mode 100644 index 0000000..b213cb4 --- /dev/null +++ b/IntegrationTests/DeletePartitionedTKeyTests.cs @@ -0,0 +1,137 @@ +using IntegrationTests.Infrastructure; +using MongoDB.Bson.Serialization.Attributes; +using MongoDbGenericRepository.Models; +using NUnit.Framework; +using System; +using System.Threading.Tasks; + +namespace IntegrationTests +{ + public class DeleteTestsPartitionedTKeyDocument : IPartitionedDocument, IDocument + { + [BsonId] + public Guid Id { get; set; } + public int Version { get; set; } + public DeleteTestsPartitionedTKeyDocument() + { + Id = Guid.NewGuid(); + Version = 2; + PartitionKey = "TestPartitionKey"; + } + public string PartitionKey { get; set; } + public string SomeContent { get; set; } + } + + public class DeletePartitionedTKeyTests : BaseMongoDbRepositoryTests + { + [Test] + public void PartitionedDeleteOne() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.DeleteOne(document); + // Assert + Assert.AreEqual(1, result); + Assert.IsFalse(SUT.Any(e => e.Id == document.Id, PartitionKey)); + } + + [Test] + public void PartitionedDeleteOneLinq() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.DeleteOne(e => e.Id == document.Id, PartitionKey); + // Assert + Assert.AreEqual(1, result); + Assert.IsFalse(SUT.Any(e => e.Id == document.Id, PartitionKey)); + } + + [Test] + public async Task PartitionedDeleteOneAsync() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.DeleteOneAsync(document); + // Assert + Assert.AreEqual(1, result); + Assert.IsFalse(SUT.Any(e => e.Id == document.Id, PartitionKey)); + } + + [Test] + public async Task PartitionedDeleteOneAsyncLinq() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.DeleteOneAsync(e => e.Id == document.Id, PartitionKey); + // Assert + Assert.AreEqual(1, result); + Assert.IsFalse(SUT.Any(e => e.Id == document.Id, PartitionKey)); + } + + [Test] + public async Task PartitionedDeleteManyAsyncLinq() + { + // Arrange + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = "DeleteManyAsyncLinqContent"); + SUT.AddMany(documents); + // Act + var result = await SUT.DeleteManyAsync(e => e.SomeContent == "DeleteManyAsyncLinqContent", PartitionKey); + // Assert + Assert.AreEqual(5, result); + Assert.IsFalse(SUT.Any(e => e.SomeContent == "DeleteManyAsyncLinqContent", PartitionKey)); + } + + [Test] + public async Task PartitionedDeleteManyAsync() + { + // Arrange + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = "DeleteManyAsyncLinqContent"); + SUT.AddMany(documents); + // Act + var result = await SUT.DeleteManyAsync(documents); + // Assert + Assert.AreEqual(5, result); + Assert.IsFalse(SUT.Any(e => e.SomeContent == "DeleteManyAsyncLinqContent", PartitionKey)); + } + + [Test] + public void PartitionedDeleteManyLinq() + { + // Arrange + var content = "DeleteManyLinqContent"; + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = content); + SUT.AddMany(documents); + // Act + var result = SUT.DeleteMany(e => e.SomeContent == content, PartitionKey); + // Assert + Assert.AreEqual(5, result); + Assert.IsFalse(SUT.Any(e => e.SomeContent == content, PartitionKey)); + } + + [Test] + public void PartitionedDeleteMany() + { + // Arrange + var content = "DeleteManyContent"; + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = content); + SUT.AddMany(documents); + // Act + var result = SUT.DeleteMany(documents); + // Assert + Assert.AreEqual(5, result); + Assert.IsFalse(SUT.Any(e => e.SomeContent == content, PartitionKey)); + } + } +} diff --git a/IntegrationTests/DeleteTKeyTests.cs b/IntegrationTests/DeleteTKeyTests.cs new file mode 100644 index 0000000..dd90c09 --- /dev/null +++ b/IntegrationTests/DeleteTKeyTests.cs @@ -0,0 +1,135 @@ +using IntegrationTests.Infrastructure; +using MongoDB.Bson.Serialization.Attributes; +using MongoDbGenericRepository.Models; +using NUnit.Framework; +using System; +using System.Threading.Tasks; + +namespace IntegrationTests +{ + public class DeleteTestsTKeyDocument : IDocument + { + [BsonId] + public Guid Id { get; set; } + public int Version { get; set; } + public DeleteTestsTKeyDocument() + { + Id = Guid.NewGuid(); + Version = 2; + } + public string SomeContent { get; set; } + } + + public class DeleteTKeyTests : BaseMongoDbRepositoryTests + { + [Test] + public void DeleteOne() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.DeleteOne(document); + // Assert + Assert.AreEqual(1, result); + Assert.IsFalse(SUT.Any(e => e.Id == document.Id)); + } + + [Test] + public void DeleteOneLinq() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.DeleteOne(e => e.Id == document.Id); + // Assert + Assert.AreEqual(1, result); + Assert.IsFalse(SUT.Any(e => e.Id == document.Id)); + } + + [Test] + public async Task DeleteOneAsync() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.DeleteOneAsync(document); + // Assert + Assert.AreEqual(1, result); + Assert.IsFalse(SUT.Any(e => e.Id == document.Id)); + } + + [Test] + public async Task DeleteOneAsyncLinq() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.DeleteOneAsync(e => e.Id == document.Id); + // Assert + Assert.AreEqual(1, result); + Assert.IsFalse(SUT.Any(e => e.Id == document.Id)); + } + + [Test] + public async Task DeleteManyAsyncLinq() + { + // Arrange + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = "DeleteManyAsyncLinqContent"); + SUT.AddMany(documents); + // Act + var result = await SUT.DeleteManyAsync(e => e.SomeContent == "DeleteManyAsyncLinqContent"); + // Assert + Assert.AreEqual(5, result); + Assert.IsFalse(SUT.Any(e => e.SomeContent == "DeleteManyAsyncLinqContent")); + } + + [Test] + public async Task DeleteManyAsync() + { + // Arrange + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = "DeleteManyAsyncLinqContent"); + SUT.AddMany(documents); + // Act + var result = await SUT.DeleteManyAsync(documents); + // Assert + Assert.AreEqual(5, result); + Assert.IsFalse(SUT.Any(e => e.SomeContent == "DeleteManyAsyncLinqContent")); + } + + [Test] + public void DeleteManyLinq() + { + // Arrange + var content = "DeleteManyLinqContent"; + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = content); + SUT.AddMany(documents); + // Act + var result = SUT.DeleteMany(e => e.SomeContent == content); + // Assert + Assert.AreEqual(5, result); + Assert.IsFalse(SUT.Any(e => e.SomeContent == content)); + } + + [Test] + public void DeleteMany() + { + // Arrange + var content = "DeleteManyContent"; + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = content); + SUT.AddMany(documents); + // Act + var result = SUT.DeleteMany(documents); + // Assert + Assert.AreEqual(5, result); + Assert.IsFalse(SUT.Any(e => e.SomeContent == content)); + } + } +} diff --git a/IntegrationTests/GroupTests/GroupingTests.cs b/IntegrationTests/GroupTests/GroupingTests.cs new file mode 100644 index 0000000..751af45 --- /dev/null +++ b/IntegrationTests/GroupTests/GroupingTests.cs @@ -0,0 +1,108 @@ +using IntegrationTests.Infrastructure; +using MongoDbGenericRepository.Models; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace IntegrationTests.GroupTests +{ + public class GroupingTestsDocument : Document + { + public GroupingTestsDocument() + { + Version = 2; + Children = new List(); + } + public string SomeContent { get; set; } + public int GroupingKey { get; set; } + public List Children { get; set; } + } + + public class ProjectedGroup + { + public int Key { get; set; } + public List Content { get; set; } + } + + public class GroupingTests : BaseMongoDbRepositoryTests + { + [Test] + public void GroupByTProjection() + { + // Arrange + var documents = CreateTestDocuments(5); + for(var i = 0; i < documents.Count - 2; i++) + { + documents[i].GroupingKey = 1; + documents[i].SomeContent = $"content-{i}"; + } + for (var i = 3; i < documents.Count; i++) + { + documents[i].GroupingKey = 2; + documents[i].SomeContent = $"content-{i}"; + } + SUT.AddMany(documents); + + // Act + + var result = SUT.GroupBy( + e => e.GroupingKey, g => new ProjectedGroup { + Key = g.Key, + Content = g.Select(doc => doc.SomeContent).ToList() + }); + + // Assert + var key1Group = result.First(e => e.Key == 1); + Assert.NotNull(key1Group); + Assert.AreEqual(3, key1Group.Content.Count); + var key2Group = result.First(e => e.Key == 2); + Assert.NotNull(key2Group); + Assert.AreEqual(2, key2Group.Content.Count); + } + + [Test] + public void FilteredGroupByTProjection() + { + // Arrange + var documents = CreateTestDocuments(5); + for (var i = 0; i < documents.Count - 2; i++) + { + documents[i].GroupingKey = 4; + documents[i].SomeContent = $"content-{i}"; + } + for (var i = 3; i < documents.Count; i++) + { + documents[i].GroupingKey = 5; + documents[i].SomeContent = $"content-{i}"; + } + var guid1 = Guid.NewGuid().ToString("n"); + var guid2 = Guid.NewGuid().ToString("n"); + for (var i = 0; i < documents.Count - 1; i++) + { + documents[i].Children = new List { + new Child(guid1, guid2) + }; + } + + SUT.AddMany(documents); + + // Act + var result = SUT.GroupBy( + e => e.Children.Any(c => c.Type == guid1), + e => e.GroupingKey, g => new ProjectedGroup + { + Key = g.Key, + Content = g.Select(doc => doc.SomeContent).ToList() + }); + + // Assert + var key1Group = result.First(e => e.Key == 4); + Assert.NotNull(key1Group); + Assert.AreEqual(3, key1Group.Content.Count); + var key2Group = result.First(e => e.Key == 5); + Assert.NotNull(key2Group); + Assert.AreEqual(1, key2Group.Content.Count); + } + } +} diff --git a/IntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs b/IntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs index 74d358e..1c7b43f 100644 --- a/IntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs +++ b/IntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs @@ -5,7 +5,7 @@ using System.Configuration; namespace IntegrationTests.Infrastructure { - public class BaseMongoDbRepositoryTests where T : Document, new() + public class BaseMongoDbRepositoryTests where T : class, new() { public T CreateTestDocument() { diff --git a/IntegrationTests/Infrastructure/Child.cs b/IntegrationTests/Infrastructure/Child.cs new file mode 100644 index 0000000..cf9d1ec --- /dev/null +++ b/IntegrationTests/Infrastructure/Child.cs @@ -0,0 +1,14 @@ +namespace IntegrationTests.Infrastructure +{ + public class Child + { + public Child(string type, string value) + { + Type = type; + Value = value; + } + + public string Type { get; set; } + public string Value { get; set; } + } +} diff --git a/IntegrationTests/IntegrationTests.csproj b/IntegrationTests/IntegrationTests.csproj index 58a2d21..d3bb63c 100644 --- a/IntegrationTests/IntegrationTests.csproj +++ b/IntegrationTests/IntegrationTests.csproj @@ -31,16 +31,13 @@ - ..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDB.Bson.dll + ..\packages\MongoDB.Bson.2.4.4\lib\net45\MongoDB.Bson.dll - ..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDB.Driver.dll + ..\packages\MongoDB.Driver.2.4.4\lib\net45\MongoDB.Driver.dll - ..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDB.Driver.Core.dll - - - ..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDbGenericRepository.dll + ..\packages\MongoDB.Driver.Core.2.4.4\lib\net45\MongoDB.Driver.Core.dll ..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll @@ -49,24 +46,37 @@ - - ..\packages\MongoDbGenericRepository.1.2.1\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + True + + + + + + + + + + + + @@ -78,5 +88,11 @@ + + + {efc776c4-2af3-440c-be80-3fbe335817a5} + MongoDbGenericRepository + + \ No newline at end of file diff --git a/IntegrationTests/ProjectPartitionedTKeyTests.cs b/IntegrationTests/ProjectPartitionedTKeyTests.cs new file mode 100644 index 0000000..9d80dde --- /dev/null +++ b/IntegrationTests/ProjectPartitionedTKeyTests.cs @@ -0,0 +1,143 @@ +using IntegrationTests.Infrastructure; +using MongoDB.Bson.Serialization.Attributes; +using MongoDbGenericRepository.Models; +using NUnit.Framework; +using System; +using System.Linq; +using System.Threading.Tasks; + +namespace IntegrationTests +{ + + public class ProjectTestsPartitionedTKeyDocument : IDocument, IPartitionedDocument + { + [BsonId] + public Guid Id { get; set; } + public int Version { get; set; } + public ProjectTestsPartitionedTKeyDocument() + { + Id = Guid.NewGuid(); + Version = 2; + PartitionKey = "TestPartitionKey"; + Nested = new NestedTKey(); + } + public string PartitionKey { get; set; } + public NestedTKey Nested { get; set; } + public string SomeContent { get; set; } + } + + public class ProjectPartitionedTKeyTests : BaseMongoDbRepositoryTests + { + [Test] + public async Task PartitionedProjectOneAsync() + { + // Arrange + const string someContent = "ProjectOneAsyncContent"; + var someDate = DateTime.UtcNow; + var document = CreateTestDocument(); + document.SomeContent = someContent; + document.Nested.SomeDate = someDate; + SUT.AddOne(document); + // Act + var result = await SUT.ProjectOneAsync( + x => x.Id == document.Id, + x => new MyProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }, + PartitionKey); + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(someContent, result.SomeContent); + Assert.AreEqual(someDate.Minute, result.SomeDate.Minute); + Assert.AreEqual(someDate.Second, result.SomeDate.Second); + } + + [Test] + public void PartitionedProjectOne() + { + // Arrange + const string someContent = "ProjectOneContent"; + var someDate = DateTime.UtcNow; + var document = CreateTestDocument(); + document.SomeContent = someContent; + document.Nested.SomeDate = someDate; + SUT.AddOne(document); + // Act + var result = SUT.ProjectOne( + x => x.Id == document.Id, + x => new MyProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }, + PartitionKey); + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(someContent, result.SomeContent); + Assert.AreEqual(someDate.Minute, result.SomeDate.Minute); + Assert.AreEqual(someDate.Second, result.SomeDate.Second); + } + + [Test] + public async Task PartitionedProjectManyAsync() + { + // Arrange + const string someContent = "ProjectManyAsyncContent"; + var someDate = DateTime.UtcNow; + var document = CreateTestDocuments(5); + document.ForEach(e => + { + e.SomeContent = someContent; + e.Nested.SomeDate = someDate; + }); + + SUT.AddMany(document); + // Act + var result = await SUT.ProjectManyAsync( + x => x.SomeContent == someContent, + x => new MyProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }, + PartitionKey); + // Assert + Assert.AreEqual(5, result.Count); + Assert.AreEqual(someContent, result.First().SomeContent); + Assert.AreEqual(someDate.Minute, result.First().SomeDate.Minute); + Assert.AreEqual(someDate.Second, result.First().SomeDate.Second); + } + + [Test] + public void PartitionedProjectMany() + { + // Arrange + const string someContent = "ProjectManyContent"; + var someDate = DateTime.UtcNow; + var document = CreateTestDocuments(5); + document.ForEach(e => + { + e.SomeContent = someContent; + e.Nested.SomeDate = someDate; + }); + + SUT.AddMany(document); + // Act + var result = SUT.ProjectMany( + x => x.SomeContent == someContent, + x => new MyProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }, + PartitionKey); + // Assert + Assert.AreEqual(5, result.Count); + Assert.AreEqual(someContent, result.First().SomeContent); + Assert.AreEqual(someDate.Minute, result.First().SomeDate.Minute); + Assert.AreEqual(someDate.Second, result.First().SomeDate.Second); + } + } +} diff --git a/IntegrationTests/ProjectTKeyTests.cs b/IntegrationTests/ProjectTKeyTests.cs new file mode 100644 index 0000000..cec8606 --- /dev/null +++ b/IntegrationTests/ProjectTKeyTests.cs @@ -0,0 +1,150 @@ +using IntegrationTests.Infrastructure; +using MongoDB.Bson.Serialization.Attributes; +using MongoDbGenericRepository.Models; +using NUnit.Framework; +using System; +using System.Linq; +using System.Threading.Tasks; + +namespace IntegrationTests +{ + public class NestedTKey + { + public DateTime SomeDate { get; set; } + } + + public class MyProjectionTKey + { + public DateTime SomeDate { get; set; } + public string SomeContent { get; set; } + } + + public class ProjectTestsTKeyDocument : IDocument + { + [BsonId] + public Guid Id { get; set; } + public int Version { get; set; } + public ProjectTestsTKeyDocument() + { + Id = Guid.NewGuid(); + Version = 2; + Nested = new NestedTKey + { + SomeDate = DateTime.UtcNow + }; + } + public string SomeContent { get; set; } + public NestedTKey Nested { get; set; } + } + + public class ProjectTKeyTests : BaseMongoDbRepositoryTests + { + [Test] + public async Task ProjectOneAsync() + { + // Arrange + const string someContent = "ProjectOneAsyncContent"; + var someDate = DateTime.UtcNow; + var document = CreateTestDocument(); + document.SomeContent = someContent; + document.Nested.SomeDate = someDate; + SUT.AddOne(document); + // Act + var result = await SUT.ProjectOneAsync( + x => x.Id == document.Id, + x => new MyProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }); + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(someContent, result.SomeContent); + Assert.AreEqual(someDate.Minute, result.SomeDate.Minute); + Assert.AreEqual(someDate.Second, result.SomeDate.Second); + } + + [Test] + public void ProjectOne() + { + // Arrange + const string someContent = "ProjectOneContent"; + var someDate = DateTime.UtcNow; + var document = CreateTestDocument(); + document.SomeContent = someContent; + document.Nested.SomeDate = someDate; + SUT.AddOne(document); + // Act + var result = SUT.ProjectOne( + x => x.Id == document.Id, + x => new MyProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }); + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(someContent, result.SomeContent); + Assert.AreEqual(someDate.Minute, result.SomeDate.Minute); + Assert.AreEqual(someDate.Second, result.SomeDate.Second); + } + + [Test] + public async Task ProjectManyAsync() + { + // Arrange + const string someContent = "ProjectManyAsyncContent"; + var someDate = DateTime.UtcNow; + var document = CreateTestDocuments(5); + document.ForEach(e => + { + e.SomeContent = someContent; + e.Nested.SomeDate = someDate; + }); + + SUT.AddMany(document); + // Act + var result = await SUT.ProjectManyAsync( + x => x.SomeContent == someContent, + x => new MyProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }); + // Assert + Assert.AreEqual(5, result.Count); + Assert.AreEqual(someContent, result.First().SomeContent); + Assert.AreEqual(someDate.Minute, result.First().SomeDate.Minute); + Assert.AreEqual(someDate.Second, result.First().SomeDate.Second); + } + + [Test] + public void ProjectMany() + { + // Arrange + const string someContent = "ProjectManyContent"; + var someDate = DateTime.UtcNow; + var document = CreateTestDocuments(5); + document.ForEach(e => + { + e.SomeContent = someContent; + e.Nested.SomeDate = someDate; + }); + + SUT.AddMany(document); + // Act + var result = SUT.ProjectMany( + x => x.SomeContent == someContent, + x => new MyProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }); + // Assert + Assert.AreEqual(5, result.Count); + Assert.AreEqual(someContent, result.First().SomeContent); + Assert.AreEqual(someDate.Minute, result.First().SomeDate.Minute); + Assert.AreEqual(someDate.Second, result.First().SomeDate.Second); + } + } +} diff --git a/IntegrationTests/ReadPartitionedTKeyTests.cs b/IntegrationTests/ReadPartitionedTKeyTests.cs new file mode 100644 index 0000000..ceab08e --- /dev/null +++ b/IntegrationTests/ReadPartitionedTKeyTests.cs @@ -0,0 +1,189 @@ +using IntegrationTests.Infrastructure; +using MongoDB.Bson.Serialization.Attributes; +using MongoDbGenericRepository.Models; +using NUnit.Framework; +using System; +using System.Threading.Tasks; + +namespace IntegrationTests +{ + public class ReadTestsPartitionedTKeyDocument : IDocument, IPartitionedDocument + { + [BsonId] + public Guid Id { get; set; } + public int Version { get; set; } + public ReadTestsPartitionedTKeyDocument() + { + Id = Guid.NewGuid(); + Version = 2; + PartitionKey = "TestPartitionKey"; + } + public string PartitionKey { get; set; } + public string SomeContent { get; set; } + } + + [TestFixture] + public class ReadPartitionedTKeyTests : BaseMongoDbRepositoryTests + { + [Test] + public async Task PartitionedGetByIdAsync() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.GetByIdAsync(document.Id, PartitionKey); + // Assert + Assert.IsNotNull(result); + } + + [Test] + public void PartitionedGetById() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.GetById(document.Id, PartitionKey); + // Assert + Assert.IsNotNull(result); + } + + [Test] + public async Task PartitionedGetOneAsync() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.GetOneAsync(x => x.Id == document.Id, PartitionKey); + // Assert + Assert.IsNotNull(result); + } + + [Test] + public void PartitionedGetOne() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.GetOne(x => x.Id == document.Id, PartitionKey); + // Assert + Assert.IsNotNull(result); + } + + [Test] + public void PartitionedGetCursor() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var cursor = SUT.GetCursor(x => x.Id == document.Id, PartitionKey); + var count = cursor.Count(); + // Assert + Assert.AreEqual(1, count); + } + + [Test] + public async Task PartitionedAnyAsyncReturnsTrue() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.AnyAsync(x => x.Id == document.Id, PartitionKey); + // Assert + Assert.AreEqual(true, result); + } + + [Test] + public async Task PartitionedAnyAsyncReturnsFalse() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.AnyAsync(x => x.Id == Guid.NewGuid(), PartitionKey); + // Assert + Assert.AreEqual(false, result); + } + + [Test] + public void PartitionedAnyReturnsTrue() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.Any(x => x.Id == document.Id, PartitionKey); + // Assert + Assert.AreEqual(true, result); + } + + [Test] + public void PartitionedAnyReturnsFalse() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.Any(x => x.Id == Guid.NewGuid(), PartitionKey); + // Assert + Assert.AreEqual(false, result); + } + + [Test] + public async Task PartitionedGetAllAsync() + { + // Arrange + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = "GetAllAsyncContent"); + SUT.AddMany(documents); + // Act + var result = await SUT.GetAllAsync(x => x.SomeContent == "GetAllAsyncContent", PartitionKey); + // Assert + Assert.AreEqual(5, result.Count); + } + + [Test] + public void PartitionedGetAll() + { + // Arrange + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = "GetAllContent"); + SUT.AddMany(documents); + // Act + var result = SUT.GetAll(x => x.SomeContent == "GetAllContent", PartitionKey); + // Assert + Assert.AreEqual(5, result.Count); + } + + [Test] + public async Task PartitionedCountAsync() + { + // Arrange + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = "CountAsyncContent"); + SUT.AddMany(documents); + // Act + var result = await SUT.CountAsync(x => x.SomeContent == "CountAsyncContent", PartitionKey); + // Assert + Assert.AreEqual(5, result); + } + + [Test] + public void PartitionedCount() + { + // Arrange + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = "CountContent"); + SUT.AddMany(documents); + // Act + var result = SUT.Count(x => x.SomeContent == "CountContent", PartitionKey); + // Assert + Assert.AreEqual(5, result); + } + } +} diff --git a/IntegrationTests/ReadTKeyTests.cs b/IntegrationTests/ReadTKeyTests.cs new file mode 100644 index 0000000..e2e6330 --- /dev/null +++ b/IntegrationTests/ReadTKeyTests.cs @@ -0,0 +1,187 @@ +using IntegrationTests.Infrastructure; +using MongoDB.Bson.Serialization.Attributes; +using MongoDbGenericRepository.Models; +using NUnit.Framework; +using System; +using System.Threading.Tasks; + +namespace IntegrationTests +{ + public class ReadTestsTKeyDocument : IDocument + { + [BsonId] + public Guid Id { get; set; } + public int Version { get; set; } + public ReadTestsTKeyDocument() + { + Id = Guid.NewGuid(); + Version = 2; + } + public string SomeContent { get; set; } + } + + [TestFixture] + public class ReadTKeyTests : BaseMongoDbRepositoryTests + { + [Test] + public async Task GetByIdAsync() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.GetByIdAsync(document.Id); + // Assert + Assert.IsNotNull(result); + } + + [Test] + public void GetById() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.GetById(document.Id); + // Assert + Assert.IsNotNull(result); + } + + [Test] + public async Task GetOneAsync() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.GetOneAsync(x => x.Id == document.Id); + // Assert + Assert.IsNotNull(result); + } + + [Test] + public void GetOne() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.GetOne(x => x.Id == document.Id); + // Assert + Assert.IsNotNull(result); + } + + [Test] + public void GetCursor() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var cursor = SUT.GetCursor(x => x.Id == document.Id); + var count = cursor.Count(); + // Assert + Assert.AreEqual(1, count); + } + + [Test] + public async Task AnyAsyncReturnsTrue() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.AnyAsync(x => x.Id == document.Id); + // Assert + Assert.AreEqual(true, result); + } + + [Test] + public async Task AnyAsyncReturnsFalse() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.AnyAsync(x => x.Id == Guid.NewGuid()); + // Assert + Assert.AreEqual(false, result); + } + + [Test] + public void AnyReturnsTrue() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.Any(x => x.Id == document.Id); + // Assert + Assert.AreEqual(true, result); + } + + [Test] + public void AnyReturnsFalse() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.Any(x => x.Id == Guid.NewGuid()); + // Assert + Assert.AreEqual(false, result); + } + + [Test] + public async Task GetAllAsync() + { + // Arrange + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = "GetAllAsyncContent"); + SUT.AddMany(documents); + // Act + var result = await SUT.GetAllAsync(x => x.SomeContent == "GetAllAsyncContent"); + // Assert + Assert.AreEqual(5, result.Count); + } + + [Test] + public void GetAll() + { + // Arrange + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = "GetAllContent"); + SUT.AddMany(documents); + // Act + var result = SUT.GetAll(x => x.SomeContent == "GetAllContent"); + // Assert + Assert.AreEqual(5, result.Count); + } + + [Test] + public async Task CountAsync() + { + // Arrange + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = "CountAsyncContent"); + SUT.AddMany(documents); + // Act + var result = await SUT.CountAsync(x => x.SomeContent == "CountAsyncContent"); + // Assert + Assert.AreEqual(5, result); + } + + [Test] + public void Count() + { + // Arrange + var documents = CreateTestDocuments(5); + documents.ForEach(e => e.SomeContent = "CountContent"); + SUT.AddMany(documents); + // Act + var result = SUT.Count(x => x.SomeContent == "CountContent"); + // Assert + Assert.AreEqual(5, result); + } + } +} diff --git a/IntegrationTests/UpdatePartitionedTKeyTests.cs b/IntegrationTests/UpdatePartitionedTKeyTests.cs new file mode 100644 index 0000000..41c66cf --- /dev/null +++ b/IntegrationTests/UpdatePartitionedTKeyTests.cs @@ -0,0 +1,117 @@ +using IntegrationTests.Infrastructure; +using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Driver; +using MongoDbGenericRepository.Models; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace IntegrationTests +{ + + public class UpdateTestsPartitionedTKeyDocument : IDocument, IPartitionedDocument + { + [BsonId] + public Guid Id { get; set; } + public int Version { get; set; } + public UpdateTestsPartitionedTKeyDocument() + { + Id = Guid.NewGuid(); + Version = 2; + PartitionKey = "TestPartitionKey"; + Children = new List(); + } + public string PartitionKey { get; set; } + public string SomeContent { get; set; } + public List Children { get; set; } + } + + [TestFixture] + public class UpdatePartitionedTKeyTests : BaseMongoDbRepositoryTests + { + [Test] + public void PartitionedUpdateOne() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + document.SomeContent = "UpdateOneContent"; + // Act + var result = SUT.UpdateOne(document); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id, PartitionKey); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual("UpdateOneContent", updatedDocument.SomeContent); + } + + [Test] + public async Task PartitionedUpdateOneAsync() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + document.SomeContent = "UpdateOneAsyncContent"; + // Act + var result = await SUT.UpdateOneAsync(document); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id, PartitionKey); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual("UpdateOneAsyncContent", updatedDocument.SomeContent); + } + + [Test] + public async Task UpdateOneAsyncWithUpdateDefinition() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + var updateDef = Builders.Update.AddToSetEach(p => p.Children, childrenToAdd); + + // Act + var result = await SUT.UpdateOneAsync(document, updateDef); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id, document.PartitionKey); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + + [Test] + public void UpdateOneWithUpdateDefinition() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + var updateDef = Builders.Update.AddToSetEach(p => p.Children, childrenToAdd); + + // Act + var result = SUT.UpdateOne(document, updateDef); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id, document.PartitionKey); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + } +} diff --git a/IntegrationTests/UpdatePartitionedTests.cs b/IntegrationTests/UpdatePartitionedTests.cs index 3c0fa8a..fd7e3f9 100644 --- a/IntegrationTests/UpdatePartitionedTests.cs +++ b/IntegrationTests/UpdatePartitionedTests.cs @@ -1,6 +1,8 @@ using IntegrationTests.Infrastructure; +using MongoDB.Driver; using MongoDbGenericRepository.Models; using NUnit.Framework; +using System.Collections.Generic; using System.Threading.Tasks; namespace IntegrationTests @@ -10,8 +12,10 @@ namespace IntegrationTests public UpdateTestsPartitionedDocument() : base("TestPartitionKey") { Version = 2; + Children = new List(); } public string SomeContent { get; set; } + public List Children { get; set; } } public class UpdatePartitionedTests : BaseMongoDbRepositoryTests @@ -47,5 +51,155 @@ namespace IntegrationTests Assert.IsNotNull(updatedDocument); Assert.AreEqual("UpdateOneAsyncContent", updatedDocument.SomeContent); } + + [Test] + public async Task UpdateOneAsyncWithUpdateDefinition() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + var updateDef = Builders.Update.AddToSetEach(p => p.Children, childrenToAdd); + + // Act + var result = await SUT.UpdateOneAsync(document, updateDef); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id, document.PartitionKey); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + + [Test] + public void UpdateOneWithUpdateDefinition() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + var updateDef = Builders.Update.AddToSetEach(p => p.Children, childrenToAdd); + + // Act + var result = SUT.UpdateOne(document, updateDef); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id, document.PartitionKey); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + + [Test] + public void UpdateOneWithFieldSelector() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + // Act + var result = SUT.UpdateOne(document, x => x.Children, childrenToAdd); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id, document.PartitionKey); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + + [Test] + public async Task UpdateOneAsyncWithFieldSelector() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + // Act + var result = await SUT.UpdateOneAsync(document, x => x.Children, childrenToAdd); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id, document.PartitionKey); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + + [Test] + public void UpdateOneWithFilterAndFieldSelector() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + // Act + var filter = Builders.Filter.Eq("Id", document.Id); + var result = SUT.UpdateOne(filter, x => x.Children, childrenToAdd, document.PartitionKey); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id, document.PartitionKey); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + + [Test] + public async Task UpdateOneAsyncWithFilterAndFieldSelector() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + // Act + var filter = Builders.Filter.Eq("Id", document.Id); + var result = await SUT.UpdateOneAsync(filter, x => x.Children, childrenToAdd, document.PartitionKey); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id, document.PartitionKey); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } } } diff --git a/IntegrationTests/UpdateTKeyTests.cs b/IntegrationTests/UpdateTKeyTests.cs new file mode 100644 index 0000000..f981196 --- /dev/null +++ b/IntegrationTests/UpdateTKeyTests.cs @@ -0,0 +1,195 @@ +using IntegrationTests.Infrastructure; +using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Driver; +using MongoDbGenericRepository.Models; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace IntegrationTests +{ + + public class UpdateTestsTKeyDocument : IDocument + { + [BsonId] + public Guid Id { get; set; } + public int Version { get; set; } + public UpdateTestsTKeyDocument() + { + Id = Guid.NewGuid(); + Version = 2; + Children = new List(); + } + public string SomeContent { get; set; } + public List Children { get; set; } + } + + [TestFixture] + public class UpdateTKeyTests : BaseMongoDbRepositoryTests + { + [Test] + public void UpdateOne() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + document.SomeContent = "UpdateOneContent"; + // Act + var result = SUT.UpdateOne(document); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual("UpdateOneContent", updatedDocument.SomeContent); + } + + [Test] + public async Task UpdateOneAsync() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + document.SomeContent = "UpdateOneAsyncContent"; + // Act + var result = await SUT.UpdateOneAsync(document); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual("UpdateOneAsyncContent", updatedDocument.SomeContent); + } + + [Test] + public async Task UpdateOneAsyncWithUpdateDefinition() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + var updateDef = Builders.Update.AddToSetEach(p => p.Children, childrenToAdd); + // Act + var result = await SUT.UpdateOneAsync(document, updateDef); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + + [Test] + public void UpdateOneWithUpdateDefinition() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + var updateDef = Builders.Update.AddToSetEach(p => p.Children, childrenToAdd); + + // Act + var result = SUT.UpdateOne(document, updateDef); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + + [Test] + public void UpdateOneWithFieldSelector() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + var filter = Builders.Filter.Eq("Id", document.Id); + + // Act + var result = SUT.UpdateOne>(document, x => x.Children, childrenToAdd); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + + [Test] + public async Task UpdateOneAsyncWithFieldSelector() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + var filter = Builders.Filter.Eq("Id", document.Id); + + // Act + var result = await SUT.UpdateOneAsync>(document, x => x.Children, childrenToAdd); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + + [Test] + public void UpdateOneWithFilterAndFieldSelector() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + var filter = Builders.Filter.Eq("Id", document.Id); + + // Act + var result = SUT.UpdateOne>(filter, x => x.Children, childrenToAdd); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + } +} diff --git a/IntegrationTests/UpdateTests.cs b/IntegrationTests/UpdateTests.cs index 328c3f3..ee5bb17 100644 --- a/IntegrationTests/UpdateTests.cs +++ b/IntegrationTests/UpdateTests.cs @@ -1,6 +1,8 @@ using IntegrationTests.Infrastructure; +using MongoDB.Driver; using MongoDbGenericRepository.Models; using NUnit.Framework; +using System.Collections.Generic; using System.Threading.Tasks; namespace IntegrationTests @@ -10,8 +12,10 @@ namespace IntegrationTests public UpdateTestsDocument() { Version = 2; + Children = new List(); } public string SomeContent { get; set; } + public List Children { get; set; } } public class UpdateTests : BaseMongoDbRepositoryTests @@ -47,5 +51,155 @@ namespace IntegrationTests Assert.IsNotNull(updatedDocument); Assert.AreEqual("UpdateOneAsyncContent", updatedDocument.SomeContent); } + + [Test] + public async Task UpdateOneAsyncWithUpdateDefinition() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + var updateDef = Builders.Update.AddToSetEach(p => p.Children, childrenToAdd); + + // Act + var result = await SUT.UpdateOneAsync(document, updateDef); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + + [Test] + public void UpdateOneWithUpdateDefinition() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + var updateDef = Builders.Update.AddToSetEach(p => p.Children, childrenToAdd); + + // Act + var result = SUT.UpdateOne(document, updateDef); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + + [Test] + public void UpdateOneWithFieldSelector() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + // Act + var result = SUT.UpdateOne(document, x => x.Children, childrenToAdd); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + + [Test] + public async Task UpdateOneAsyncWithFieldSelector() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + // Act + var result = await SUT.UpdateOneAsync(document, x => x.Children, childrenToAdd); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + + [Test] + public void UpdateOneWithFilterAndFieldSelector() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + // Act + var filter = Builders.Filter.Eq("Id", document.Id); + var result = SUT.UpdateOne(filter, x => x.Children, childrenToAdd); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } + + [Test] + public async Task UpdateOneAsyncWithFilterAndFieldSelector() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + var childrenToAdd = new List + { + new Child("testType1", "testValue1"), + new Child("testType2", "testValue2") + }; + + // Act + var filter = Builders.Filter.Eq("Id", document.Id); + var result = await SUT.UpdateOneAsync(filter, x => x.Children, childrenToAdd); + // Assert + Assert.IsTrue(result); + var updatedDocument = SUT.GetById(document.Id); + Assert.IsNotNull(updatedDocument); + Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type); + Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value); + Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type); + Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value); + } } } diff --git a/IntegrationTests/packages.config b/IntegrationTests/packages.config index 8ef186d..383927f 100644 --- a/IntegrationTests/packages.config +++ b/IntegrationTests/packages.config @@ -3,8 +3,8 @@ - - + + \ No newline at end of file diff --git a/MongoDbGenericRepository/BaseMongoDbRepository.cs b/MongoDbGenericRepository/BaseMongoDbRepository.cs index d9e90e5..3059736 100644 --- a/MongoDbGenericRepository/BaseMongoDbRepository.cs +++ b/MongoDbGenericRepository/BaseMongoDbRepository.cs @@ -1,808 +1,2192 @@ -using MongoDB.Driver; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using System.Linq.Expressions; -using MongoDbGenericRepository.Models; -using System.Linq; - -namespace MongoDbGenericRepository -{ - /// - /// The IBaseMongoRepository exposes the functionality of the BaseMongoRepository. - /// - public interface IBaseMongoRepository - { - /// - /// The connection string. - /// - string ConnectionString { get; set; } - /// - /// The database name. - /// - string DatabaseName { get; set; } - - #region Create - - /// - /// Asynchronously adds a document to the collection. - /// - /// - /// The document you want to add. - Task AddOneAsync(TDocument document) where TDocument : IDocument; - - /// - /// Adds a document to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// - /// The document you want to add. - void AddOne(TDocument document) where TDocument : IDocument; - - /// - /// Asynchronously adds a list of documents to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// - /// The document you want to add. - Task AddManyAsync(IEnumerable documents) where TDocument : IDocument; - - /// - /// Adds a list of documents to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// - /// The document you want to add. - void AddMany(IEnumerable documents) where TDocument : IDocument; - - #endregion - - #region Read - - /// - /// Asynchronously returns one document given its id. - /// - /// - /// The Id of the document you want to get. - /// An optional partition key. - Task GetByIdAsync(Guid id, string partitionKey = null) where TDocument : IDocument; - - /// - /// Returns one document given its id. - /// - /// - /// The Id of the document you want to get. - /// An optional partition key. - TDocument GetById(Guid id, string partitionKey = null) where TDocument : IDocument; - - /// - /// Asynchronously returns one document given an expression filter. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - Task GetOneAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; - - /// - /// Returns one document given an expression filter. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - TDocument GetOne(Expression> filter, string partitionKey = null) where TDocument : IDocument; - - /// - /// Returns a collection cursor. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - IFindFluent GetCursor(Expression> filter, string partitionKey = null) where TDocument : IDocument; - - /// - /// Asynchronously returns true if any of the document of the collection matches the filter condition. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - Task AnyAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; - - /// - /// Returns true if any of the document of the collection matches the filter condition. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - bool Any(Expression> filter, string partitionKey = null) where TDocument : IDocument; - - /// - /// Asynchronously returns a list of the documents matching the filter condition. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - Task> GetAllAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; - - /// - /// Returns a list of the documents matching the filter condition. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - List GetAll(Expression> filter, string partitionKey = null) where TDocument : IDocument; - - /// - /// Asynchronously counts how many documents match the filter condition. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - Task CountAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; - - /// - /// Counts how many documents match the filter condition. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - long Count(Expression> filter, string partitionKey = null) where TDocument : IDocument; - - #endregion - - #region Update - - /// - /// Asynchronously Updates a document. - /// - /// - /// The document with the modifications you want to persist. - Task UpdateOneAsync(TDocument modifiedDocument) where TDocument : IDocument; - - /// - /// Updates a document. - /// - /// - /// The document with the modifications you want to persist. - bool UpdateOne(TDocument modifiedDocument) where TDocument : IDocument; - - #endregion - - #region Delete - - /// - /// Asynchronously deletes a document. - /// - /// - /// The document you want to delete. - /// The number of documents deleted. - Task DeleteOneAsync(TDocument document) where TDocument : IDocument; - - /// - /// Asynchronously deletes a document matching the condition of the LINQ expression filter. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - /// The number of documents deleted. - Task DeleteOneAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; - - /// - /// Deletes a document. - /// - /// - /// The document you want to delete. - /// The number of documents deleted. - long DeleteOne(TDocument document) where TDocument : IDocument; - - /// - /// Deletes a document matching the condition of the LINQ expression filter. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - /// The number of documents deleted. - long DeleteOne(Expression> filter, string partitionKey = null) where TDocument : IDocument; - - /// - /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - /// The number of documents deleted. - Task DeleteManyAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; - - /// - /// Asynchronously deletes a list of documents. - /// - /// - /// The list of documents to delete. - /// The number of documents deleted. - Task DeleteManyAsync(IEnumerable documents) where TDocument : IDocument; - - /// - /// Deletes a list of documents. - /// - /// - /// The list of documents to delete. - /// The number of documents deleted. - long DeleteMany(IEnumerable documents) where TDocument : IDocument; - - /// - /// Deletes the documents matching the condition of the LINQ expression filter. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - /// The number of documents deleted. - long DeleteMany(Expression> filter, string partitionKey = null) where TDocument : IDocument; - - #endregion - - #region Project - - /// - /// Asynchronously returns a projected document matching the filter condition. - /// - /// - /// - /// - /// The projection expression. - /// An optional partition key. - Task ProjectOneAsync(Expression> filter, Expression> projection, string partitionKey = null) - where TDocument : IDocument - where TProjection : class; - - /// - /// Returns a projected document matching the filter condition. - /// - /// - /// - /// - /// The projection expression. - /// An optional partition key. - TProjection ProjectOne(Expression> filter, Expression> projection, string partitionKey = null) - where TDocument : IDocument - where TProjection : class; - - /// - /// Asynchronously returns a list of projected documents matching the filter condition. - /// - /// - /// - /// - /// The projection expression. - /// An optional partition key. - Task> ProjectManyAsync(Expression> filter, Expression> projection, string partitionKey = null) - where TDocument : IDocument - where TProjection : class; - - /// - /// Asynchronously returns a list of projected documents matching the filter condition. - /// - /// - /// - /// - /// The projection expression. - /// An optional partition key. - List ProjectMany(Expression> filter, Expression> projection, string partitionKey = null) - where TDocument : IDocument - where TProjection : class; - - #endregion - - } - - /// - /// The base Repository, it is meant to be inherited from by your custom custom MongoRepository implementation. - /// Its constructor must be given a connection string and a database name. - /// - public abstract class BaseMongoRepository : IBaseMongoRepository - { - /// - /// The connection string. - /// - public string ConnectionString { get; set; } - /// - /// The database name. - /// - public string DatabaseName { get; set; } - - /// - /// The constructor taking a connection string and a database name. - /// - /// The connection string of the MongoDb server. - /// The name of the database against which you want to perform operations. - protected BaseMongoRepository(string connectionString, string databaseName) - { - MongoDbContext = new MongoDbContext(connectionString, databaseName); - } - - /// - /// The contructor taking a . - /// - /// A mongodb context implementing - protected BaseMongoRepository(IMongoDbContext mongoDbContext) - { - MongoDbContext = mongoDbContext; - } - - /// - /// The MongoDbContext - /// - protected IMongoDbContext MongoDbContext = null; - - #region Create - - /// - /// Asynchronously adds a document to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// - /// The document you want to add. - public async Task AddOneAsync(TDocument document) where TDocument : IDocument - { - FormatDocument(document); - await HandlePartitioned(document).InsertOneAsync(document); - } - - /// - /// Adds a document to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// - /// The document you want to add. - public void AddOne(TDocument document) where TDocument : IDocument - { - FormatDocument(document); - HandlePartitioned(document).InsertOne(document); - } - - /// - /// Asynchronously adds a list of documents to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// - /// The documents you want to add. - public async Task AddManyAsync(IEnumerable documents) where TDocument : IDocument - { - if (!documents.Any()) - { - return; - } - foreach (var doc in documents) - { - FormatDocument(doc); - } - await HandlePartitioned(documents.FirstOrDefault()).InsertManyAsync(documents); - } - - /// - /// Adds a list of documents to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// - /// The documents you want to add. - public void AddMany(IEnumerable documents) where TDocument : IDocument - { - if (!documents.Any()) - { - return; - } - foreach (var document in documents) - { - FormatDocument(document); - } - HandlePartitioned(documents.FirstOrDefault()).InsertMany(documents.ToList()); - } - - #endregion Create - - #region Read - - /// - /// Asynchronously returns one document given its id. - /// - /// - /// The Id of the document you want to get. - /// An optional partition key. - public async Task GetByIdAsync(Guid id, string partitionKey = null) where TDocument : IDocument - { - var filter = Builders.Filter.Eq("Id", id); - return await HandlePartitioned(partitionKey).Find(filter).FirstOrDefaultAsync(); - } - - /// - /// Returns one document given its id. - /// - /// - /// The Id of the document you want to get. - /// An optional partition key. - public TDocument GetById(Guid id, string partitionKey = null) where TDocument : IDocument - { - var filter = Builders.Filter.Eq("Id", id); - return HandlePartitioned(partitionKey).Find(filter).FirstOrDefault(); - } - - /// - /// Asynchronously returns one document given an expression filter. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - public async Task GetOneAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return await HandlePartitioned(partitionKey).Find(filter).FirstOrDefaultAsync(); - } - - /// - /// Returns one document given an expression filter. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - public TDocument GetOne(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return HandlePartitioned(partitionKey).Find(filter).FirstOrDefault(); - } - - /// - /// Returns a collection cursor. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - public IFindFluent GetCursor(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return HandlePartitioned(partitionKey).Find(filter); - } - - /// - /// Returns true if any of the document of the collection matches the filter condition. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - public async Task AnyAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - var count = await HandlePartitioned(partitionKey).CountAsync(filter); - return (count > 0); - } - - /// - /// Returns true if any of the document of the collection matches the filter condition. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - public bool Any(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - var count = HandlePartitioned(partitionKey).Count(filter); - return (count > 0); - } - - /// - /// Asynchronously returns a list of the documents matching the filter condition. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - public async Task> GetAllAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return await HandlePartitioned(partitionKey).Find(filter).ToListAsync(); - } - - /// - /// Returns a list of the documents matching the filter condition. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - public List GetAll(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return HandlePartitioned(partitionKey).Find(filter).ToList(); - } - - /// - /// Asynchronously counts how many documents match the filter condition. - /// - /// - /// A LINQ expression filter. - /// An optional partitionKey - public async Task CountAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return await HandlePartitioned(partitionKey).CountAsync(filter); - } - - /// - /// Counts how many documents match the filter condition. - /// - /// - /// A LINQ expression filter. - /// An optional partitionKey - public long Count(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return HandlePartitioned(partitionKey).Find(filter).Count(); - } - - #endregion - - #region Update - - /// - /// Asynchronously Updates a document. - /// - /// - /// The document with the modifications you want to persist. - public async Task UpdateOneAsync(TDocument modifiedDocument) where TDocument : IDocument - { - var updateRes = await HandlePartitioned(modifiedDocument).ReplaceOneAsync(x => x.Id == modifiedDocument.Id, modifiedDocument); - return updateRes.ModifiedCount == 1; - } - - /// - /// Updates a document. - /// - /// - /// The document with the modifications you want to persist. - public bool UpdateOne(TDocument modifiedDocument) where TDocument : IDocument - { - var updateRes = HandlePartitioned(modifiedDocument).ReplaceOne(x => x.Id == modifiedDocument.Id, modifiedDocument); - return updateRes.ModifiedCount == 1; - } - - #endregion Update - - #region Delete - - /// - /// Asynchronously deletes a document. - /// - /// - /// The document you want to delete. - /// The number of documents deleted. - public async Task DeleteOneAsync(TDocument document) where TDocument : IDocument - { - return (await HandlePartitioned(document).DeleteOneAsync(x => x.Id == document.Id)).DeletedCount; - } - - /// - /// Deletes a document. - /// - /// - /// The document you want to delete. - /// The number of documents deleted. - public long DeleteOne(TDocument document) where TDocument : IDocument - { - return HandlePartitioned(document).DeleteOne(x => x.Id == document.Id).DeletedCount; - } - - /// - /// Deletes a document matching the condition of the LINQ expression filter. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - /// The number of documents deleted. - public long DeleteOne(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return HandlePartitioned(partitionKey).DeleteOne(filter).DeletedCount; - } - - /// - /// Asynchronously deletes a document matching the condition of the LINQ expression filter. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - /// The number of documents deleted. - public async Task DeleteOneAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return (await HandlePartitioned(partitionKey).DeleteOneAsync(filter)).DeletedCount; - } - - /// - /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - /// The number of documents deleted. - public async Task DeleteManyAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return (await HandlePartitioned(partitionKey).DeleteManyAsync(filter)).DeletedCount; - } - - /// - /// Asynchronously deletes a list of documents. - /// - /// - /// The list of documents to delete. - /// The number of documents deleted. - public async Task DeleteManyAsync(IEnumerable documents) where TDocument : IDocument - { - if (!documents.Any()) - { - return 0; - } - var idsTodelete = documents.Select(e => e.Id).ToArray(); - return (await HandlePartitioned(documents.FirstOrDefault()).DeleteManyAsync(x => idsTodelete.Contains(x.Id))).DeletedCount; - } - - /// - /// Deletes a list of documents. - /// - /// - /// The list of documents to delete. - /// The number of documents deleted. - public long DeleteMany(IEnumerable documents) where TDocument : IDocument - { - if (!documents.Any()) - { - return 0; - } - var idsTodelete = documents.Select(e => e.Id).ToArray(); - return HandlePartitioned(documents.FirstOrDefault()).DeleteMany(x => idsTodelete.Contains(x.Id)).DeletedCount; - } - - /// - /// Deletes the documents matching the condition of the LINQ expression filter. - /// - /// - /// A LINQ expression filter. - /// An optional partition key. - /// The number of documents deleted. - public long DeleteMany(Expression> filter, string partitionKey = null) where TDocument : IDocument - { - return HandlePartitioned(partitionKey).DeleteMany(filter).DeletedCount; - } - - #endregion Delete - - #region Project - - /// - /// Asynchronously returns a projected document matching the filter condition. - /// - /// - /// - /// - /// The projection expression. - /// An optional partition key. - public async Task ProjectOneAsync(Expression> filter, Expression> projection, string partitionKey = null) - where TDocument : IDocument - where TProjection : class - { - return await HandlePartitioned(partitionKey).Find(filter) - .Project(projection) - .FirstOrDefaultAsync(); - } - - /// - /// Returns a projected document matching the filter condition. - /// - /// - /// - /// - /// The projection expression. - /// An optional partition key. - public TProjection ProjectOne(Expression> filter, Expression> projection, string partitionKey = null) - where TDocument : IDocument - where TProjection : class - { - return HandlePartitioned(partitionKey).Find(filter) - .Project(projection) - .FirstOrDefault(); - } - - /// - /// Asynchronously returns a list of projected documents matching the filter condition. - /// - /// - /// - /// - /// The projection expression. - /// An optional partition key. - public async Task> ProjectManyAsync(Expression> filter, Expression> projection, string partitionKey = null) - where TDocument : IDocument - where TProjection : class - { - return await HandlePartitioned(partitionKey).Find(filter) - .Project(projection) - .ToListAsync(); - } - - /// - /// Asynchronously returns a list of projected documents matching the filter condition. - /// - /// - /// - /// - /// The projection expression. - /// An optional partition key. - public List ProjectMany(Expression> filter, Expression> projection, string partitionKey = null) - where TDocument : IDocument - where TProjection : class - { - return HandlePartitioned(partitionKey).Find(filter) - .Project(projection) - .ToList(); - } - - #endregion - - /// - /// Asynchronously returns a paginated list of the documents matching the filter condition. - /// - /// - /// - /// 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 async Task> GetPaginatedAsync(Expression> filter, int skipNumber = 0, int takeNumber = 50, string partitionKey = null) where TDocument : IDocument - { - return await HandlePartitioned(partitionKey).Find(filter).Skip(skipNumber).Limit(takeNumber).ToListAsync(); - } - - #region Find And Update - - /// - /// GetAndUpdateOne with filter - /// - /// - /// - /// - /// - /// - public async Task GetAndUpdateOne(FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options) where TDocument : IDocument - { - return await GetCollection().FindOneAndUpdateAsync(filter, update, options); - } - - #endregion Find And Update - - #region Private Methods - - private IMongoCollection GetCollection(string partitionKey) where TDocument : IDocument - { - return MongoDbContext.GetCollection(partitionKey); - } - - private IMongoCollection GetCollection() where TDocument : IDocument - { - return MongoDbContext.GetCollection(); - } - - private IMongoCollection HandlePartitioned(TDocument document) where TDocument : IDocument - { - if (document is IPartitionedDocument) - { - return GetCollection(((IPartitionedDocument)document).PartitionKey); - } - return GetCollection(); - } - - private IMongoCollection HandlePartitioned(string partitionKey) where TDocument : IDocument - { - if (!string.IsNullOrEmpty(partitionKey)) - { - return GetCollection(partitionKey); - } - return GetCollection(); - } - - private void FormatDocument(TDocument document) where TDocument : IDocument - { - if (document == null) - { - throw new ArgumentNullException(nameof(document)); - } - if (document.Id == default(Guid)) - { - document.Id = Guid.NewGuid(); - } - } - - #endregion - } +using MongoDB.Driver; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using System.Linq.Expressions; +using MongoDbGenericRepository.Models; +using System.Linq; + +namespace MongoDbGenericRepository +{ + /// + /// The IBaseMongoRepository exposes the functionality of the BaseMongoRepository. + /// + public interface IBaseMongoRepository + { + /// + /// The connection string. + /// + string ConnectionString { get; set; } + /// + /// The database name. + /// + string DatabaseName { get; set; } + + #region Create + + /// + /// Asynchronously adds a document to the collection. + /// + /// The type representing a Document. + /// The document you want to add. + Task AddOneAsync(TDocument document) where TDocument : IDocument; + + /// + /// Adds a document to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The document you want to add. + void AddOne(TDocument document) where TDocument : IDocument; + + /// + /// Asynchronously adds a list of documents to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The document you want to add. + Task AddManyAsync(IEnumerable documents) where TDocument : IDocument; + + /// + /// Adds a list of documents to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The document you want to add. + void AddMany(IEnumerable documents) where TDocument : IDocument; + + #endregion + + #region Create TKey + + /// + /// Asynchronously adds a document to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to add. + Task AddOneAsync(TDocument document) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Adds a document to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to add. + void AddOne(TDocument document) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously adds a list of documents to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The documents you want to add. + Task AddManyAsync(IEnumerable documents) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Adds a list of documents to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The documents you want to add. + void AddMany(IEnumerable documents) + where TDocument : IDocument + where TKey : IEquatable; + + #endregion + + #region Read + + /// + /// Asynchronously returns one document given its id. + /// + /// The type representing a Document. + /// The Id of the document you want to get. + /// An optional partition key. + Task GetByIdAsync(Guid id, string partitionKey = null) where TDocument : IDocument; + + /// + /// Returns one document given its id. + /// + /// The type representing a Document. + /// The Id of the document you want to get. + /// An optional partition key. + TDocument GetById(Guid id, string partitionKey = null) where TDocument : IDocument; + + /// + /// Asynchronously returns one document given an expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + Task GetOneAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; + + /// + /// Returns one document given an expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + TDocument GetOne(Expression> filter, string partitionKey = null) where TDocument : IDocument; + + /// + /// Returns a collection cursor. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + IFindFluent GetCursor(Expression> filter, string partitionKey = null) where TDocument : IDocument; + + /// + /// Asynchronously returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + Task AnyAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + bool Any(Expression> filter, string partitionKey = null) where TDocument : IDocument; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + Task> GetAllAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; + + /// + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + List GetAll(Expression> filter, string partitionKey = null) where TDocument : IDocument; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + Task CountAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + long Count(Expression> filter, string partitionKey = null) where TDocument : IDocument; + + #endregion + + #region Read TKey + + /// + /// Asynchronously returns one document given its id. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The Id of the document you want to get. + /// An optional partition key. + Task GetByIdAsync(TKey id, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns one document given its id. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The Id of the document you want to get. + /// An optional partition key. + TDocument GetById(TKey id, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns one document given an expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + Task GetOneAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns one document given an expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + TDocument GetOne(Expression> filter, string partitionKey = null) + 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 LINQ expression filter. + /// An optional partition key. + IFindFluent GetCursor(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + Task AnyAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + bool Any(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + Task> GetAllAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + List GetAll(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partitionKey + Task CountAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partitionKey + long Count(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + #endregion + + #region Update + + /// + /// Asynchronously Updates a document. + /// + /// The type representing a Document. + /// The document with the modifications you want to persist. + Task UpdateOneAsync(TDocument modifiedDocument) where TDocument : IDocument; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The document with the modifications you want to persist. + bool UpdateOne(TDocument modifiedDocument) where TDocument : IDocument; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document you want to modify. + /// The field selector. + /// The new value of the property field. + bool UpdateOne(TDocument documentToModify, Expression> field, TField value) + where TDocument : IDocument; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document you want to modify. + /// The field selector. + /// The new value of the property field. + Task UpdateOneAsync(TDocument documentToModify, Expression> field, TField value) + where TDocument : IDocument; + + /// + /// Takes a document you want to modify and applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document you want to modify. + /// The update definition for the document. + Task UpdateOneAsync(TDocument documentToModify, UpdateDefinition update) + where TDocument : IDocument; + + /// + /// Takes a document you want to modify and applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document you want to modify. + /// The update definition for the document. + bool UpdateOne(TDocument documentToModify, UpdateDefinition update) + where TDocument : IDocument; + + #endregion + + #region Update TKey + + /// + /// Asynchronously Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document with the modifications you want to persist. + Task UpdateOneAsync(TDocument modifiedDocument) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document with the modifications you want to persist. + bool UpdateOne(TDocument modifiedDocument) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Takes a document you want to modify and applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to modify. + /// The update definition for the document. + Task UpdateOneAsync(TDocument documentToModify, UpdateDefinition update) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Takes a document you want to modify and applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to modify. + /// The update definition for the document. + bool UpdateOne(TDocument documentToModify, UpdateDefinition update) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field. + /// The document you want to modify. + /// The field selector. + /// The new value of the property field. + Task UpdateOneAsync(TDocument documentToModify, Expression> field, TField value) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field. + /// The document you want to modify. + /// The field selector. + /// The new value of the property field. + bool UpdateOne(TDocument documentToModify, Expression> field, TField value) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + #endregion + + #region Delete + + /// + /// Asynchronously deletes a document. + /// + /// The type representing a Document. + /// The document you want to delete. + /// The number of documents deleted. + Task DeleteOneAsync(TDocument document) where TDocument : IDocument; + + /// + /// Asynchronously deletes a document matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + Task DeleteOneAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; + + /// + /// Deletes a document. + /// + /// The type representing a Document. + /// The document you want to delete. + /// The number of documents deleted. + long DeleteOne(TDocument document) where TDocument : IDocument; + + /// + /// Deletes a document matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + long DeleteOne(Expression> filter, string partitionKey = null) where TDocument : IDocument; + + /// + /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + Task DeleteManyAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument; + + /// + /// Asynchronously deletes a list of documents. + /// + /// The type representing a Document. + /// The list of documents to delete. + /// The number of documents deleted. + Task DeleteManyAsync(IEnumerable documents) where TDocument : IDocument; + + /// + /// Deletes a list of documents. + /// + /// The type representing a Document. + /// The list of documents to delete. + /// The number of documents deleted. + long DeleteMany(IEnumerable documents) where TDocument : IDocument; + + /// + /// Deletes the documents matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + long DeleteMany(Expression> filter, string partitionKey = null) where TDocument : IDocument; + + #endregion + + #region Delete TKey + + /// + /// Deletes a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to delete. + /// The number of documents deleted. + long DeleteOne(TDocument document) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + /// The document you want to delete. + /// The number of documents deleted. + Task DeleteOneAsync(TDocument document) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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 LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + long DeleteOne(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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 LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + Task DeleteOneAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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 LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + Task DeleteManyAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously deletes a list of documents. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The list of documents to delete. + /// The number of documents deleted. + Task DeleteManyAsync(IEnumerable documents) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Deletes a list of documents. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The list of documents to delete. + /// The number of documents deleted. + long DeleteMany(IEnumerable documents) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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 LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + long DeleteMany(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + #endregion + + #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. + /// + /// The projection expression. + /// An optional partition key. + Task ProjectOneAsync(Expression> filter, Expression> projection, string partitionKey = null) + where TDocument : IDocument + 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. + /// + /// The projection expression. + /// An optional partition key. + Task ProjectOneAsync(Expression> filter, Expression> projection, 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 representing the model you want to project to. + /// + /// The projection expression. + /// An optional partition key. + TProjection ProjectOne(Expression> filter, Expression> projection, string partitionKey = null) + where TDocument : IDocument + 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. + /// + /// The projection expression. + /// An optional partition key. + TProjection ProjectOne(Expression> filter, Expression> projection, 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 representing the model you want to project to. + /// + /// The projection expression. + /// An optional partition key. + Task> ProjectManyAsync(Expression> filter, Expression> projection, 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 of the primary key for a Document. + /// The type representing the model you want to project to. + /// + /// The projection expression. + /// An optional partition key. + Task> ProjectManyAsync(Expression> filter, Expression> projection, 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 representing the model you want to project to. + /// + /// The projection expression. + /// An optional partition key. + List ProjectMany(Expression> filter, Expression> projection, 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 of the primary key for a Document. + /// The type representing the model you want to project to. + /// + /// The projection expression. + /// An optional partition key. + List ProjectMany(Expression> filter, Expression> projection, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + #endregion + + /// + /// Asynchronously returns a paginated list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// + /// 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(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. + /// + /// 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(Expression> filter, int skipNumber = 0, int takeNumber = 50, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// GetAndUpdateOne with filter + /// + /// The type representing a Document. + /// + /// + /// + /// + Task GetAndUpdateOne(FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options) + where TDocument : IDocument; + + /// + /// GetAndUpdateOne with filter + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// + /// + /// + /// + Task GetAndUpdateOne(FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options) + where TDocument : IDocument + where TKey : IEquatable; + + #region Grouping + + /// + /// Groups a collection of documents given a grouping criteria, + /// and returns a list of projected documents. + /// + /// The type representing a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// The grouping criteria. + /// The projected group result. + /// The partition key of your document, if any. + List GroupBy( + Expression> groupingCriteria, + Expression, TProjection>> groupProjection, + string partitionKey = null) + where TDocument : IDocument + where TProjection : class, new(); + + /// Groups filtered a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// The grouping criteria. + /// The projected group result. + /// The partition key of your document, if any. + /// + List GroupBy(Expression> filter, + Expression> selector, + Expression, TProjection>> projection, + string partitionKey = null) + where TDocument : IDocument + where TProjection : class, new(); + + #endregion + } + + /// + /// The base Repository, it is meant to be inherited from by your custom custom MongoRepository implementation. + /// Its constructor must be given a connection string and a database name. + /// + public abstract class BaseMongoRepository : IBaseMongoRepository + { + /// + /// The connection string. + /// + public string ConnectionString { get; set; } + + /// + /// The database name. + /// + public string DatabaseName { get; set; } + + /// + /// The constructor taking a connection string and a database name. + /// + /// The connection string of the MongoDb server. + /// The name of the database against which you want to perform operations. + protected BaseMongoRepository(string connectionString, string databaseName) + { + MongoDbContext = new MongoDbContext(connectionString, databaseName); + } + + /// + /// The contructor taking a . + /// + /// A mongodb context implementing + protected BaseMongoRepository(IMongoDbContext mongoDbContext) + { + MongoDbContext = mongoDbContext; + } + + /// + /// The MongoDbContext + /// + protected IMongoDbContext MongoDbContext = null; + + #region Create + + /// + /// Asynchronously adds a document to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The document you want to add. + public async Task AddOneAsync(TDocument document) where TDocument : IDocument + { + FormatDocument(document); + await HandlePartitioned(document).InsertOneAsync(document); + } + + /// + /// Adds a document to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The document you want to add. + public void AddOne(TDocument document) where TDocument : IDocument + { + FormatDocument(document); + HandlePartitioned(document).InsertOne(document); + } + + /// + /// Asynchronously adds a list of documents to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The documents you want to add. + public async Task AddManyAsync(IEnumerable documents) where TDocument : IDocument + { + if (!documents.Any()) + { + return; + } + foreach (var doc in documents) + { + FormatDocument(doc); + } + await HandlePartitioned(documents.FirstOrDefault()).InsertManyAsync(documents); + } + + /// + /// Adds a list of documents to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The documents you want to add. + public void AddMany(IEnumerable documents) where TDocument : IDocument + { + if (!documents.Any()) + { + return; + } + foreach (var document in documents) + { + FormatDocument(document); + } + HandlePartitioned(documents.FirstOrDefault()).InsertMany(documents.ToList()); + } + + #endregion Create + + #region Create TKey + + /// + /// Asynchronously adds a document to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to add. + public async Task AddOneAsync(TDocument document) + where TDocument : IDocument + where TKey : IEquatable + { + FormatDocument(document); + await HandlePartitioned(document).InsertOneAsync(document); + } + + /// + /// Adds a document to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to add. + public void AddOne(TDocument document) + where TDocument : IDocument + where TKey : IEquatable + { + FormatDocument(document); + HandlePartitioned(document).InsertOne(document); + } + + /// + /// Asynchronously adds a list of documents to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The documents you want to add. + public async Task AddManyAsync(IEnumerable documents) + where TDocument : IDocument + where TKey : IEquatable + { + if (!documents.Any()) + { + return; + } + foreach (var doc in documents) + { + FormatDocument(doc); + } + await HandlePartitioned(documents.FirstOrDefault()).InsertManyAsync(documents); + } + + /// + /// Adds a list of documents to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The documents you want to add. + public void AddMany(IEnumerable documents) + where TDocument : IDocument + where TKey : IEquatable + { + if (!documents.Any()) + { + return; + } + foreach (var document in documents) + { + FormatDocument(document); + } + HandlePartitioned(documents.FirstOrDefault()).InsertMany(documents.ToList()); + } + + + #endregion + + #region Read + + /// + /// Asynchronously returns one document given its id. + /// + /// The type representing a Document. + /// The Id of the document you want to get. + /// An optional partition key. + public async Task GetByIdAsync(Guid id, string partitionKey = null) where TDocument : IDocument + { + var filter = Builders.Filter.Eq("Id", id); + return await HandlePartitioned(partitionKey).Find(filter).FirstOrDefaultAsync(); + } + + /// + /// Returns one document given its id. + /// + /// The type representing a Document. + /// The Id of the document you want to get. + /// An optional partition key. + public TDocument GetById(Guid id, string partitionKey = null) where TDocument : IDocument + { + var filter = Builders.Filter.Eq("Id", id); + return HandlePartitioned(partitionKey).Find(filter).FirstOrDefault(); + } + + /// + /// Asynchronously returns one document given an expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + public async Task GetOneAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument + { + return await HandlePartitioned(partitionKey).Find(filter).FirstOrDefaultAsync(); + } + + /// + /// Returns one document given an expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + public TDocument GetOne(Expression> filter, string partitionKey = null) where TDocument : IDocument + { + return HandlePartitioned(partitionKey).Find(filter).FirstOrDefault(); + } + + /// + /// Returns a collection cursor. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + public IFindFluent GetCursor(Expression> filter, string partitionKey = null) where TDocument : IDocument + { + return HandlePartitioned(partitionKey).Find(filter); + } + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + public async Task AnyAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument + { + var count = await HandlePartitioned(partitionKey).CountAsync(filter); + return (count > 0); + } + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + public bool Any(Expression> filter, string partitionKey = null) where TDocument : IDocument + { + var count = HandlePartitioned(partitionKey).Count(filter); + return (count > 0); + } + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + public async Task> GetAllAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument + { + return await HandlePartitioned(partitionKey).Find(filter).ToListAsync(); + } + + /// + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + public List GetAll(Expression> filter, string partitionKey = null) where TDocument : IDocument + { + return HandlePartitioned(partitionKey).Find(filter).ToList(); + } + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partitionKey + public async Task CountAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument + { + return await HandlePartitioned(partitionKey).CountAsync(filter); + } + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partitionKey + public long Count(Expression> filter, string partitionKey = null) where TDocument : IDocument + { + return HandlePartitioned(partitionKey).Find(filter).Count(); + } + + #endregion + + #region Read TKey + + /// + /// Asynchronously returns one document given its id. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The Id of the document you want to get. + /// An optional partition key. + public async Task GetByIdAsync(TKey id, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + var filter = Builders.Filter.Eq("Id", id); + return await HandlePartitioned(partitionKey).Find(filter).FirstOrDefaultAsync(); + } + + /// + /// Returns one document given its id. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The Id of the document you want to get. + /// An optional partition key. + public TDocument GetById(TKey id, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + var filter = Builders.Filter.Eq("Id", id); + return HandlePartitioned(partitionKey).Find(filter).FirstOrDefault(); + } + + /// + /// Asynchronously returns one document given an expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + public async Task GetOneAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return await HandlePartitioned(partitionKey).Find(filter).FirstOrDefaultAsync(); + } + + /// + /// Returns one document given an expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + public TDocument GetOne(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return HandlePartitioned(partitionKey).Find(filter).FirstOrDefault(); + } + + /// + /// Returns a collection cursor. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + public IFindFluent GetCursor(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return HandlePartitioned(partitionKey).Find(filter); + } + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + public async Task AnyAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + var count = await HandlePartitioned(partitionKey).CountAsync(filter); + return (count > 0); + } + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + public bool Any(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + var count = HandlePartitioned(partitionKey).Count(filter); + return (count > 0); + } + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + public async Task> GetAllAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return await HandlePartitioned(partitionKey).Find(filter).ToListAsync(); + } + + /// + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + public List GetAll(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return HandlePartitioned(partitionKey).Find(filter).ToList(); + } + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partitionKey + public async Task CountAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return await HandlePartitioned(partitionKey).CountAsync(filter); + } + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partitionKey + public long Count(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return HandlePartitioned(partitionKey).Find(filter).Count(); + } + + #endregion + + #region Update + + /// + /// Asynchronously Updates a document. + /// + /// The type representing a Document. + /// The document with the modifications you want to persist. + public async Task UpdateOneAsync(TDocument modifiedDocument) where TDocument : IDocument + { + var updateRes = await HandlePartitioned(modifiedDocument).ReplaceOneAsync(x => x.Id == modifiedDocument.Id, modifiedDocument); + return updateRes.ModifiedCount == 1; + } + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The document with the modifications you want to persist. + public bool UpdateOne(TDocument modifiedDocument) where TDocument : IDocument + { + var updateRes = HandlePartitioned(modifiedDocument).ReplaceOne(x => x.Id == modifiedDocument.Id, modifiedDocument); + return updateRes.ModifiedCount == 1; + } + + /// + /// Takes a document you want to modify and applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document you want to modify. + /// The update definition for the document. + public async Task UpdateOneAsync(TDocument documentToModify, UpdateDefinition update) + where TDocument : IDocument + { + var filter = Builders.Filter.Eq("Id", documentToModify.Id); + var updateRes = await HandlePartitioned(documentToModify).UpdateOneAsync(filter, update); + return updateRes.ModifiedCount == 1; + } + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document you want to modify. + /// The field selector. + /// The new value of the property field. + public bool UpdateOne(TDocument documentToModify, Expression> field, TField value) + where TDocument : IDocument + { + var filter = Builders.Filter.Eq("Id", documentToModify.Id); + var updateRes = HandlePartitioned(documentToModify).UpdateOne(filter, Builders.Update.Set(field, value)); + return updateRes.ModifiedCount == 1; + } + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document you want to modify. + /// The field selector. + /// The new value of the property field. + public async Task UpdateOneAsync(TDocument documentToModify, Expression> field, TField value) + where TDocument : IDocument + { + var filter = Builders.Filter.Eq("Id", documentToModify.Id); + var updateRes = await HandlePartitioned(documentToModify).UpdateOneAsync(filter, Builders.Update.Set(field, value)); + return updateRes.ModifiedCount == 1; + } + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + public bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument + { + var collection = string.IsNullOrEmpty(partitionKey) ? GetCollection() : GetCollection(partitionKey); + var updateRes = collection.UpdateOne(filter, Builders.Update.Set(field, value)); + return updateRes.ModifiedCount == 1; + } + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + public async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument + { + var collection = string.IsNullOrEmpty(partitionKey) ? GetCollection() : GetCollection(partitionKey); + var updateRes = await collection.UpdateOneAsync(filter, Builders.Update.Set(field, value)); + return updateRes.ModifiedCount == 1; + } + + /// + /// Takes a document you want to modify and applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document you want to modify. + /// The update definition for the document. + public bool UpdateOne(TDocument documentToModify, UpdateDefinition update) + where TDocument : IDocument + { + var filter = Builders.Filter.Eq("Id", documentToModify.Id); + var updateRes = HandlePartitioned(documentToModify).UpdateOne(filter, update, new UpdateOptions { IsUpsert = true }); + return updateRes.ModifiedCount == 1; + } + + #endregion Update + + #region Update TKey + + /// + /// Asynchronously Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document with the modifications you want to persist. + public async Task UpdateOneAsync(TDocument modifiedDocument) + where TDocument : IDocument + where TKey : IEquatable + { + var filter = Builders.Filter.Eq("Id", modifiedDocument.Id); + var updateRes = await HandlePartitioned(modifiedDocument).ReplaceOneAsync(filter, modifiedDocument); + return updateRes.ModifiedCount == 1; + } + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document with the modifications you want to persist. + public bool UpdateOne(TDocument modifiedDocument) + where TDocument : IDocument + where TKey : IEquatable + { + var filter = Builders.Filter.Eq("Id", modifiedDocument.Id); + var updateRes = HandlePartitioned(modifiedDocument).ReplaceOne(filter, modifiedDocument); + return updateRes.ModifiedCount == 1; + } + + /// + /// Takes a document you want to modify and applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to modify. + /// The update definition for the document. + public async Task UpdateOneAsync(TDocument documentToModify, UpdateDefinition update) + where TDocument : IDocument + where TKey : IEquatable + { + var filter = Builders.Filter.Eq("Id", documentToModify.Id); + var updateRes = await HandlePartitioned(documentToModify).UpdateOneAsync(filter, update, new UpdateOptions { IsUpsert = true }); + return updateRes.ModifiedCount == 1; + } + + /// + /// Takes a document you want to modify and applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to modify. + /// The update definition for the document. + public bool UpdateOne(TDocument documentToModify, UpdateDefinition update) + where TDocument : IDocument + where TKey : IEquatable + { + var filter = Builders.Filter.Eq("Id", documentToModify.Id); + var updateRes = HandlePartitioned(documentToModify).UpdateOne(filter, update, new UpdateOptions { IsUpsert = true }); + return updateRes.ModifiedCount == 1; + } + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field. + /// The document you want to modify. + /// The field selector. + /// The new value of the property field. + public async Task UpdateOneAsync(TDocument documentToModify, Expression> field, TField value) + where TDocument : IDocument + where TKey : IEquatable + { + var filter = Builders.Filter.Eq("Id", documentToModify.Id); + var updateRes = await HandlePartitioned(documentToModify).UpdateOneAsync(filter, Builders.Update.Set(field, value)); + return updateRes.ModifiedCount == 1; + } + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field. + /// The document you want to modify. + /// The field selector. + /// The new value of the property field. + public bool UpdateOne(TDocument documentToModify, Expression> field, TField value) + where TDocument : IDocument + where TKey : IEquatable + { + var filter = Builders.Filter.Eq("Id", documentToModify.Id); + var updateRes = HandlePartitioned(documentToModify).UpdateOne(filter, Builders.Update.Set(field, value)); + return updateRes.ModifiedCount == 1; + } + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + public async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + var collection = string.IsNullOrEmpty(partitionKey) ? GetCollection() : GetCollection(partitionKey); + var updateRes = await collection.UpdateOneAsync(filter, Builders.Update.Set(field, value)); + return updateRes.ModifiedCount == 1; + } + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the field. + /// The document filter. + /// The field selector. + /// The new value of the property field. + public bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + var collection = string.IsNullOrEmpty(partitionKey) ? GetCollection() : GetCollection(partitionKey); + var updateRes = collection.UpdateOne(filter, Builders.Update.Set(field, value)); + return updateRes.ModifiedCount == 1; + } + + #endregion Update + + #region Delete + + /// + /// Asynchronously deletes a document. + /// + /// The type representing a Document. + /// The document you want to delete. + /// The number of documents deleted. + public async Task DeleteOneAsync(TDocument document) where TDocument : IDocument + { + return (await HandlePartitioned(document).DeleteOneAsync(x => x.Id == document.Id)).DeletedCount; + } + + /// + /// Deletes a document. + /// + /// The type representing a Document. + /// The document you want to delete. + /// The number of documents deleted. + public long DeleteOne(TDocument document) where TDocument : IDocument + { + return HandlePartitioned(document).DeleteOne(x => x.Id == document.Id).DeletedCount; + } + + /// + /// Deletes a document matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + public long DeleteOne(Expression> filter, string partitionKey = null) where TDocument : IDocument + { + return HandlePartitioned(partitionKey).DeleteOne(filter).DeletedCount; + } + + /// + /// Asynchronously deletes a document matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + public async Task DeleteOneAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument + { + return (await HandlePartitioned(partitionKey).DeleteOneAsync(filter)).DeletedCount; + } + + /// + /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + public async Task DeleteManyAsync(Expression> filter, string partitionKey = null) where TDocument : IDocument + { + return (await HandlePartitioned(partitionKey).DeleteManyAsync(filter)).DeletedCount; + } + + /// + /// Asynchronously deletes a list of documents. + /// + /// The type representing a Document. + /// The list of documents to delete. + /// The number of documents deleted. + public async Task DeleteManyAsync(IEnumerable documents) where TDocument : IDocument + { + if (!documents.Any()) + { + return 0; + } + var idsTodelete = documents.Select(e => e.Id).ToArray(); + return (await HandlePartitioned(documents.FirstOrDefault()).DeleteManyAsync(x => idsTodelete.Contains(x.Id))).DeletedCount; + } + + /// + /// Deletes a list of documents. + /// + /// The type representing a Document. + /// The list of documents to delete. + /// The number of documents deleted. + public long DeleteMany(IEnumerable documents) where TDocument : IDocument + { + if (!documents.Any()) + { + return 0; + } + var idsTodelete = documents.Select(e => e.Id).ToArray(); + return HandlePartitioned(documents.FirstOrDefault()).DeleteMany(x => idsTodelete.Contains(x.Id)).DeletedCount; + } + + /// + /// Deletes the documents matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + public long DeleteMany(Expression> filter, string partitionKey = null) where TDocument : IDocument + { + return HandlePartitioned(partitionKey).DeleteMany(filter).DeletedCount; + } + + #endregion Delete + + #region Delete TKey + + /// + /// Deletes a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to delete. + /// The number of documents deleted. + public long DeleteOne(TDocument document) + where TDocument : IDocument + where TKey : IEquatable + { + var filter = Builders.Filter.Eq("Id", document.Id); + return HandlePartitioned(document).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. + /// The document you want to delete. + /// The number of documents deleted. + public async Task DeleteOneAsync(TDocument document) + where TDocument : IDocument + where TKey : IEquatable + { + var filter = Builders.Filter.Eq("Id", document.Id); + return (await HandlePartitioned(document).DeleteOneAsync(filter)).DeletedCount; + } + + /// + /// 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 LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + public long DeleteOne(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + 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 LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + public async Task DeleteOneAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return (await HandlePartitioned(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 LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + public async Task DeleteManyAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return (await HandlePartitioned(partitionKey).DeleteManyAsync(filter)).DeletedCount; + } + + /// + /// Asynchronously deletes a list of documents. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The list of documents to delete. + /// The number of documents deleted. + public async Task DeleteManyAsync(IEnumerable documents) + where TDocument : IDocument + where TKey : IEquatable + { + if (!documents.Any()) + { + return 0; + } + var idsTodelete = documents.Select(e => e.Id).ToArray(); + return (await HandlePartitioned(documents.FirstOrDefault()).DeleteManyAsync(x => idsTodelete.Contains(x.Id))).DeletedCount; + } + + /// + /// Deletes a list of documents. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The list of documents to delete. + /// The number of documents deleted. + public long DeleteMany(IEnumerable documents) + where TDocument : IDocument + where TKey : IEquatable + { + if (!documents.Any()) + { + return 0; + } + var idsTodelete = documents.Select(e => e.Id).ToArray(); + return HandlePartitioned(documents.FirstOrDefault()).DeleteMany(x => idsTodelete.Contains(x.Id)).DeletedCount; + } + + /// + /// 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 LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + public long DeleteMany(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return HandlePartitioned(partitionKey).DeleteMany(filter).DeletedCount; + } + + #endregion + + #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. + /// + /// The projection expression. + /// An optional partition key. + public async Task ProjectOneAsync(Expression> filter, Expression> projection, string partitionKey = null) + where TDocument : IDocument + where TProjection : class + { + return await HandlePartitioned(partitionKey).Find(filter) + .Project(projection) + .FirstOrDefaultAsync(); + } + + /// + /// 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. + /// + /// The projection expression. + /// An optional partition key. + public async Task ProjectOneAsync(Expression> filter, Expression> projection, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return await HandlePartitioned(partitionKey).Find(filter) + .Project(projection) + .FirstOrDefaultAsync(); + } + + /// + /// Returns a projected document matching the filter condition. + /// + /// The type representing a Document. + /// The type representing the model you want to project to. + /// + /// The projection expression. + /// An optional partition key. + public TProjection ProjectOne(Expression> filter, Expression> projection, string partitionKey = null) + where TDocument : IDocument + where TProjection : class + { + return HandlePartitioned(partitionKey).Find(filter) + .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. + /// + /// The projection expression. + /// An optional partition key. + public TProjection ProjectOne(Expression> filter, Expression> projection, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return HandlePartitioned(partitionKey).Find(filter) + .Project(projection) + .FirstOrDefault(); + } + + /// + /// 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. + /// + /// The projection expression. + /// An optional partition key. + public async Task> ProjectManyAsync(Expression> filter, Expression> projection, string partitionKey = null) + where TDocument : IDocument + where TProjection : class + { + return await HandlePartitioned(partitionKey).Find(filter) + .Project(projection) + .ToListAsync(); + } + + /// + /// 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. + /// + /// The projection expression. + /// An optional partition key. + public async Task> ProjectManyAsync(Expression> filter, Expression> projection, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return await HandlePartitioned(partitionKey).Find(filter) + .Project(projection) + .ToListAsync(); + } + + /// + /// 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. + /// + /// The projection expression. + /// An optional partition key. + public List ProjectMany(Expression> filter, Expression> projection, string partitionKey = null) + where TDocument : IDocument + where TProjection : class + { + return HandlePartitioned(partitionKey).Find(filter) + .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. + /// The document filter. + /// The projection expression. + /// An optional partition key. + public List ProjectMany(Expression> filter, Expression> projection, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class + { + return HandlePartitioned(partitionKey).Find(filter) + .Project(projection) + .ToList(); + } + + #endregion + + #region Grouping + + /// + /// Groups a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// The grouping criteria. + /// The projected group result. + /// The partition key of your document, if any. + public List GroupBy( + Expression> groupingCriteria, + Expression, TProjection>> groupProjection, + string partitionKey = null) + where TDocument : IDocument + where TProjection : class, new() + { + var collection = string.IsNullOrEmpty(partitionKey) ? GetCollection() : GetCollection(partitionKey); + return collection.Aggregate() + .Group(groupingCriteria, groupProjection) + .ToList(); + + } + + /// Groups filtered a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// The grouping criteria. + /// The projected group result. + /// The partition key of your document, if any. + /// + public List GroupBy(Expression> filter, + Expression> selector, + Expression, TProjection>> projection, + string partitionKey = null) + where TDocument : IDocument + where TProjection : class, new() + { + var collection = string.IsNullOrEmpty(partitionKey) ? GetCollection() : GetCollection(partitionKey); + return collection.Aggregate() + .Match(Builders.Filter.Where(filter)) + .Group(selector, projection) + .ToList(); + } + + + #endregion + + /// + /// Asynchronously returns a paginated list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// + /// 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 async Task> GetPaginatedAsync(Expression> filter, int skipNumber = 0, int takeNumber = 50, string partitionKey = null) + where TDocument : IDocument + { + 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. + /// + /// 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 async Task> GetPaginatedAsync(Expression> filter, int skipNumber = 0, int takeNumber = 50, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + { + return await HandlePartitioned(partitionKey).Find(filter).Skip(skipNumber).Limit(takeNumber).ToListAsync(); + } + + #region Find And Update + + /// + /// GetAndUpdateOne with filter + /// + /// The type representing a Document. + /// + /// + /// + /// + public async Task GetAndUpdateOne(FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options) where TDocument : IDocument + { + return await GetCollection().FindOneAndUpdateAsync(filter, update, options); + } + + /// + /// GetAndUpdateOne with filter + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// + /// + /// + /// + public async Task GetAndUpdateOne(FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetCollection().FindOneAndUpdateAsync(filter, update, options); + } + + #endregion Find And Update + + #region Private Methods + + private IMongoCollection GetCollection(string partitionKey) where TDocument : IDocument + { + return MongoDbContext.GetCollection(partitionKey); + } + + private IMongoCollection GetCollection() where TDocument : IDocument + { + return MongoDbContext.GetCollection(); + } + + private IMongoCollection HandlePartitioned(TDocument document) where TDocument : IDocument + { + if (document is IPartitionedDocument) + { + return GetCollection(((IPartitionedDocument)document).PartitionKey); + } + return GetCollection(); + } + + private IMongoCollection HandlePartitioned(TDocument document) + where TDocument : IDocument + where TKey : IEquatable + { + if (document is IPartitionedDocument) + { + return GetCollection(((IPartitionedDocument)document).PartitionKey); + } + return GetCollection(); + } + + private IMongoCollection HandlePartitioned(string partitionKey) where TDocument : IDocument + { + if (!string.IsNullOrEmpty(partitionKey)) + { + return GetCollection(partitionKey); + } + return GetCollection(); + } + + private void FormatDocument(TDocument document) where TDocument : IDocument + { + if (document == null) + { + throw new ArgumentNullException(nameof(document)); + } + if (document.Id == default(Guid)) + { + document.Id = Guid.NewGuid(); + } + } + + private IMongoCollection GetCollection(string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbContext.GetCollection(partitionKey); + } + + private IMongoCollection GetCollection() + where TDocument : IDocument + where TKey : IEquatable + { + return MongoDbContext.GetCollection(); + } + + private IMongoCollection HandlePartitioned(string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + if (!string.IsNullOrEmpty(partitionKey)) + { + return GetCollection(partitionKey); + } + return GetCollection(); + } + + private void FormatDocument(TDocument document) + where TDocument : IDocument + where TKey : IEquatable + { + if (document == null) + { + throw new ArgumentNullException(nameof(document)); + } + } + + #endregion + } } \ No newline at end of file diff --git a/MongoDbGenericRepository/IMongoDbContext.cs b/MongoDbGenericRepository/IMongoDbContext.cs index 31fee2a..ca2b297 100644 --- a/MongoDbGenericRepository/IMongoDbContext.cs +++ b/MongoDbGenericRepository/IMongoDbContext.cs @@ -1,5 +1,6 @@ using MongoDB.Driver; using MongoDbGenericRepository.Models; +using System; namespace MongoDbGenericRepository { @@ -31,6 +32,16 @@ namespace MongoDbGenericRepository /// The value of the partition key. IMongoCollection GetCollection(string partitionKey) where TDocument : IDocument; + /// + /// Returns a collection for a document type that has a partition key. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The value of the partition key. + IMongoCollection GetCollection(string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Drops a collection, use very carefully. /// diff --git a/MongoDbGenericRepository/Models/IDocument.cs b/MongoDbGenericRepository/Models/IDocument.cs index bdad597..3142dfb 100644 --- a/MongoDbGenericRepository/Models/IDocument.cs +++ b/MongoDbGenericRepository/Models/IDocument.cs @@ -1,4 +1,5 @@ -using System; +using MongoDB.Bson.Serialization.Attributes; +using System; namespace MongoDbGenericRepository.Models { @@ -6,16 +7,25 @@ namespace MongoDbGenericRepository.Models /// This class represents a basic document that can be stored in MongoDb. /// Your document must implement this class in order for the MongoDbRepository to handle them. /// - public interface IDocument + public interface IDocument where TKey : IEquatable { /// - /// The Guid, which must be decorated with the [BsonId] attribute + /// The Primary Key, which must be decorated with the [BsonId] attribute /// if you want the MongoDb C# driver to consider it to be the document ID. /// - Guid Id { get; set; } + [BsonId] + TKey Id { get; set; } /// /// A version number, to indicate the version of the schema. /// int Version { get; set; } } + + /// + /// This class represents a basic document that can be stored in MongoDb. + /// Your document must implement this class in order for the MongoDbRepository to handle them. + /// + public interface IDocument: IDocument + { + } } \ No newline at end of file diff --git a/MongoDbGenericRepository/Models/IPartitionedDocument.cs b/MongoDbGenericRepository/Models/IPartitionedDocument.cs index 9dbf5e2..21626ca 100644 --- a/MongoDbGenericRepository/Models/IPartitionedDocument.cs +++ b/MongoDbGenericRepository/Models/IPartitionedDocument.cs @@ -6,7 +6,7 @@ /// This can be useful if you are planning to build a Software as a Service (SaaS) Platform, or if you want to reduce indexing. /// You could for example insert Logs in different collections based on the week and year they where created, or their Log category/source. /// - public interface IPartitionedDocument : IDocument + public interface IPartitionedDocument { /// /// The partition key used to partition your collection. diff --git a/MongoDbGenericRepository/MongoDbContext.cs b/MongoDbGenericRepository/MongoDbContext.cs index dd21e9d..2223fe3 100644 --- a/MongoDbGenericRepository/MongoDbContext.cs +++ b/MongoDbGenericRepository/MongoDbContext.cs @@ -1,5 +1,6 @@ using MongoDB.Driver; using MongoDbGenericRepository.Models; +using System; namespace MongoDbGenericRepository { @@ -48,7 +49,7 @@ namespace MongoDbGenericRepository /// /// The private GetCollection method /// - /// + /// The type representing a Document. /// public IMongoCollection GetCollection() { @@ -58,17 +59,30 @@ namespace MongoDbGenericRepository /// /// Returns a collection for a document type that has a partition key. /// - /// + /// The type representing a Document. /// The value of the partition key. public IMongoCollection GetCollection(string partitionKey) where TDocument : IDocument { return Database.GetCollection(partitionKey +"-"+ Pluralize()); } + /// + /// Returns a collection for a document type that has a partition key. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The value of the partition key. + public IMongoCollection GetCollection(string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return Database.GetCollection(partitionKey + "-" + Pluralize()); + } + /// /// Drops a collection, use very carefully. /// - /// + /// The type representing a Document. public void DropCollection() { Database.DropCollection(Pluralize()); @@ -77,7 +91,7 @@ namespace MongoDbGenericRepository /// /// Drops a collection having a partitionkey, use very carefully. /// - /// + /// The type representing a Document. public void DropCollection(string partitionKey) { Database.DropCollection(partitionKey + "-" + Pluralize()); @@ -86,7 +100,7 @@ namespace MongoDbGenericRepository /// /// Very naively pluralizes a TDocument type name. /// - /// + /// The type representing a Document. /// private string Pluralize() { diff --git a/MongoDbGenericRepository/MongoDbGenericRepository.nuspec b/MongoDbGenericRepository/MongoDbGenericRepository.nuspec index 6aba088..2847dd6 100644 --- a/MongoDbGenericRepository/MongoDbGenericRepository.nuspec +++ b/MongoDbGenericRepository/MongoDbGenericRepository.nuspec @@ -2,7 +2,7 @@ MongoDbGenericRepository - 1.2.1 + 1.3 MongoDb Generic Repository Alexandre Spieser Alexandre Spieser @@ -10,7 +10,7 @@ https://github.com/alexandre-spieser/mongodb-generic-repository false A generic repository implementation using the MongoDB C# Sharp 2.0 driver. - Exposed core MongoDb driver objects and removed the AddedAtUtc property constraint from the IDocument interface. + Added support for Documents that have an Id of type TKey, and implement the IDocument{TKey} interface. Copyright 2017 (c) Alexandre Spieser. All rights reserved. MongoDb Repository Generic NoSql diff --git a/MongoDbGenericRepository/lib/net45/MongoDbGenericRepository.dll b/MongoDbGenericRepository/lib/net45/MongoDbGenericRepository.dll index c5464da..295d25d 100644 Binary files a/MongoDbGenericRepository/lib/net45/MongoDbGenericRepository.dll and b/MongoDbGenericRepository/lib/net45/MongoDbGenericRepository.dll differ diff --git a/MongoDbGenericRepository/lib/net45/MongoDbGenericRepository.xml b/MongoDbGenericRepository/lib/net45/MongoDbGenericRepository.xml index 9afe743..9a99a51 100644 --- a/MongoDbGenericRepository/lib/net45/MongoDbGenericRepository.xml +++ b/MongoDbGenericRepository/lib/net45/MongoDbGenericRepository.xml @@ -23,7 +23,7 @@ Asynchronously adds a document to the collection. - + The type representing a Document. The document you want to add. @@ -31,7 +31,7 @@ Adds a document to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The document you want to add. @@ -39,7 +39,7 @@ Asynchronously adds a list of documents to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The document you want to add. @@ -47,14 +47,50 @@ Adds a list of documents to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The document you want to add. + + + Asynchronously adds a document to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to add. + + + + Adds a document to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to add. + + + + Asynchronously adds a list of documents to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The documents you want to add. + + + + Adds a list of documents to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The documents you want to add. + Asynchronously returns one document given its id. - + The type representing a Document. The Id of the document you want to get. An optional partition key. @@ -62,7 +98,7 @@ Returns one document given its id. - + The type representing a Document. The Id of the document you want to get. An optional partition key. @@ -70,7 +106,7 @@ Asynchronously returns one document given an expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -78,7 +114,7 @@ Returns one document given an expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -86,7 +122,7 @@ Returns a collection cursor. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -94,7 +130,7 @@ Asynchronously returns true if any of the document of the collection matches the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -102,7 +138,7 @@ Returns true if any of the document of the collection matches the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -110,7 +146,7 @@ Asynchronously returns a list of the documents matching the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -118,7 +154,7 @@ Returns a list of the documents matching the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -126,7 +162,7 @@ Asynchronously counts how many documents match the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -134,29 +170,262 @@ Counts how many documents match the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. + + + Asynchronously returns one document given its id. + + The type representing a Document. + The type of the primary key for a Document. + The Id of the document you want to get. + An optional partition key. + + + + Returns one document given its id. + + The type representing a Document. + The type of the primary key for a Document. + The Id of the document you want to get. + An optional partition key. + + + + Asynchronously returns one document given an expression filter. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns one document given an expression filter. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns a collection cursor. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns true if any of the document of the collection matches the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns true if any of the document of the collection matches the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Asynchronously returns a list of the documents matching the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns a list of the documents matching the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Asynchronously counts how many documents match the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partitionKey + + + + Counts how many documents match the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partitionKey + Asynchronously Updates a document. - + The type representing a Document. The document with the modifications you want to persist. Updates a document. - + The type representing a Document. The document with the modifications you want to persist. + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The document you want to modify. + The update definition for the document. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The document you want to modify. + The update definition for the document. + + + + Asynchronously Updates a document. + + The type representing a Document. + The type of the primary key for a Document. + The document with the modifications you want to persist. + + + + Updates a document. + + The type representing a Document. + The type of the primary key for a Document. + The document with the modifications you want to persist. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to modify. + The update definition for the document. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to modify. + The update definition for the document. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + Asynchronously deletes a document. - + The type representing a Document. The document you want to delete. The number of documents deleted. @@ -164,7 +433,7 @@ Asynchronously deletes a document matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -173,7 +442,7 @@ Deletes a document. - + The type representing a Document. The document you want to delete. The number of documents deleted. @@ -181,7 +450,7 @@ Deletes a document matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -190,7 +459,7 @@ Asynchronously deletes the documents matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -199,7 +468,7 @@ Asynchronously deletes a list of documents. - + The type representing a Document. The list of documents to delete. The number of documents deleted. @@ -207,7 +476,7 @@ Deletes a list of documents. - + The type representing a Document. The list of documents to delete. The number of documents deleted. @@ -215,7 +484,83 @@ Deletes the documents matching the condition of the LINQ expression filter. - + The type representing a Document. + A LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + Deletes a document. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to delete. + The number of documents deleted. + + + + 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. + The document you want to delete. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + Asynchronously deletes a list of documents. + + The type representing a Document. + The type of the primary key for a Document. + The list of documents to delete. + The number of documents deleted. + + + + Deletes a list of documents. + + The type representing a Document. + The type of the primary key for a Document. + The list of documents to delete. + The number of documents deleted. + + + + 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 LINQ expression filter. An optional partition key. The number of documents deleted. @@ -224,8 +569,19 @@ Asynchronously returns a projected document matching the filter condition. - - + The type representing a Document. + The type representing the model you want to project to. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -234,8 +590,19 @@ Returns a projected document matching the filter condition. - - + The type representing a Document. + The type representing the model you want to project to. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -244,8 +611,19 @@ 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. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -254,12 +632,78 @@ 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. The projection expression. An optional partition key. + + + 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. + + The projection expression. + An optional partition key. + + + + Asynchronously returns a paginated list of the documents matching the filter condition. + + The type representing a Document. + + 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. + + + + 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. + + 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. + + + + GetAndUpdateOne with filter + + The type representing a Document. + + + + + + + + GetAndUpdateOne with filter + + The type representing a Document. + The type of the primary key for a Document. + + + + + + + + Groups a collection of documents given a grouping criteria, + and returns a list of projected documents. + + The type representing a Document. + The type of the grouping criteria. + The type of the projected group. + The grouping criteria. + The projected group result. + The partition key of your document, if any. + + The base Repository, it is meant to be inherited from by your custom custom MongoRepository implementation. @@ -299,7 +743,7 @@ Asynchronously adds a document to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The document you want to add. @@ -307,7 +751,7 @@ Adds a document to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The document you want to add. @@ -315,7 +759,7 @@ Asynchronously adds a list of documents to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The documents you want to add. @@ -323,14 +767,50 @@ Adds a list of documents to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. + The documents you want to add. + + + + Asynchronously adds a document to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to add. + + + + Adds a document to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to add. + + + + Asynchronously adds a list of documents to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The documents you want to add. + + + + Adds a list of documents to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. The documents you want to add. Asynchronously returns one document given its id. - + The type representing a Document. The Id of the document you want to get. An optional partition key. @@ -338,7 +818,7 @@ Returns one document given its id. - + The type representing a Document. The Id of the document you want to get. An optional partition key. @@ -346,7 +826,7 @@ Asynchronously returns one document given an expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -354,7 +834,7 @@ Returns one document given an expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -362,7 +842,7 @@ Returns a collection cursor. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -370,7 +850,7 @@ Returns true if any of the document of the collection matches the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -378,7 +858,7 @@ Returns true if any of the document of the collection matches the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -386,7 +866,7 @@ Asynchronously returns a list of the documents matching the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -394,7 +874,7 @@ Returns a list of the documents matching the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -402,7 +882,7 @@ Asynchronously counts how many documents match the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partitionKey @@ -410,7 +890,106 @@ Counts how many documents match the filter condition. - + The type representing a Document. + A LINQ expression filter. + An optional partitionKey + + + + Asynchronously returns one document given its id. + + The type representing a Document. + The type of the primary key for a Document. + The Id of the document you want to get. + An optional partition key. + + + + Returns one document given its id. + + The type representing a Document. + The type of the primary key for a Document. + The Id of the document you want to get. + An optional partition key. + + + + Asynchronously returns one document given an expression filter. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns one document given an expression filter. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns a collection cursor. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns true if any of the document of the collection matches the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns true if any of the document of the collection matches the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Asynchronously returns a list of the documents matching the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns a list of the documents matching the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Asynchronously counts how many documents match the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partitionKey + + + + Counts how many documents match the filter condition. + + The type representing a Document. + The type of the primary key for a Document. A LINQ expression filter. An optional partitionKey @@ -418,21 +997,155 @@ Asynchronously Updates a document. - + The type representing a Document. The document with the modifications you want to persist. Updates a document. - + The type representing a Document. The document with the modifications you want to persist. + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The document you want to modify. + The update definition for the document. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The document you want to modify. + The update definition for the document. + + + + Asynchronously Updates a document. + + The type representing a Document. + The type of the primary key for a Document. + The document with the modifications you want to persist. + + + + Updates a document. + + The type representing a Document. + The type of the primary key for a Document. + The document with the modifications you want to persist. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to modify. + The update definition for the document. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to modify. + The update definition for the document. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + Asynchronously deletes a document. - + The type representing a Document. The document you want to delete. The number of documents deleted. @@ -440,7 +1153,7 @@ Deletes a document. - + The type representing a Document. The document you want to delete. The number of documents deleted. @@ -448,7 +1161,7 @@ Deletes a document matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -457,7 +1170,7 @@ Asynchronously deletes a document matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -466,7 +1179,7 @@ Asynchronously deletes the documents matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -475,7 +1188,7 @@ Asynchronously deletes a list of documents. - + The type representing a Document. The list of documents to delete. The number of documents deleted. @@ -483,7 +1196,7 @@ Deletes a list of documents. - + The type representing a Document. The list of documents to delete. The number of documents deleted. @@ -491,7 +1204,83 @@ Deletes the documents matching the condition of the LINQ expression filter. - + The type representing a Document. + A LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + Deletes a document. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to delete. + The number of documents deleted. + + + + 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. + The document you want to delete. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + Asynchronously deletes a list of documents. + + The type representing a Document. + The type of the primary key for a Document. + The list of documents to delete. + The number of documents deleted. + + + + Deletes a list of documents. + + The type representing a Document. + The type of the primary key for a Document. + The list of documents to delete. + The number of documents deleted. + + + + 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 LINQ expression filter. An optional partition key. The number of documents deleted. @@ -500,8 +1289,19 @@ Asynchronously returns a projected document matching the filter condition. - - + The type representing a Document. + The type representing the model you want to project to. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -510,8 +1310,19 @@ Returns a projected document matching the filter condition. - - + The type representing a Document. + The type representing the model you want to project to. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -520,8 +1331,19 @@ 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. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -530,17 +1352,52 @@ 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. The projection expression. An optional partition key. + + + 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. + The document filter. + The projection expression. + An optional partition key. + + + + Groups a collection of documents given a grouping criteria, + and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + + The type representing a Document. + The type of the grouping criteria. + The type of the projected group. + The grouping criteria. + The projected group result. + The partition key of your document, if any. + + Asynchronously returns a paginated list of the documents matching the filter condition. - + The type representing a Document. + + 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. + + + + 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. The number of documents you want to skip. Default value is 0. The number of documents you want to take. Default value is 50. @@ -550,7 +1407,18 @@ GetAndUpdateOne with filter - + The type representing a Document. + + + + + + + + GetAndUpdateOne with filter + + The type representing a Document. + The type of the primary key for a Document. @@ -584,6 +1452,14 @@ The value of the partition key. + + + Returns a collection for a document type that has a partition key. + + The type representing a Document. + The type of the primary key for a Document. + The value of the partition key. + Drops a collection, use very carefully. @@ -622,23 +1498,29 @@ The version of the schema of the document - + This class represents a basic document that can be stored in MongoDb. Your document must implement this class in order for the MongoDbRepository to handle them. - + - The Guid, which must be decorated with the [BsonId] attribute + The Primary Key, which must be decorated with the [BsonId] attribute if you want the MongoDb C# driver to consider it to be the document ID. - + A version number, to indicate the version of the schema. + + + This class represents a basic document that can be stored in MongoDb. + Your document must implement this class in order for the MongoDbRepository to handle them. + + This class represents a document that can be inserted in a collection that can be partitioned. @@ -705,33 +1587,41 @@ The private GetCollection method - + The type representing a Document. Returns a collection for a document type that has a partition key. - + The type representing a Document. + The value of the partition key. + + + + Returns a collection for a document type that has a partition key. + + The type representing a Document. + The type of the primary key for a Document. The value of the partition key. Drops a collection, use very carefully. - + The type representing a Document. Drops a collection having a partitionkey, use very carefully. - + The type representing a Document. Very naively pluralizes a TDocument type name. - + The type representing a Document. diff --git a/MongoDbGenericRepository/lib/netstandard1.5/MongoDbGenericRepository.dll b/MongoDbGenericRepository/lib/netstandard1.5/MongoDbGenericRepository.dll index 62f6c98..284412c 100644 Binary files a/MongoDbGenericRepository/lib/netstandard1.5/MongoDbGenericRepository.dll and b/MongoDbGenericRepository/lib/netstandard1.5/MongoDbGenericRepository.dll differ diff --git a/MongoDbGenericRepository/lib/netstandard1.5/MongoDbGenericRepository.xml b/MongoDbGenericRepository/lib/netstandard1.5/MongoDbGenericRepository.xml index 9afe743..9a99a51 100644 --- a/MongoDbGenericRepository/lib/netstandard1.5/MongoDbGenericRepository.xml +++ b/MongoDbGenericRepository/lib/netstandard1.5/MongoDbGenericRepository.xml @@ -23,7 +23,7 @@ Asynchronously adds a document to the collection. - + The type representing a Document. The document you want to add. @@ -31,7 +31,7 @@ Adds a document to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The document you want to add. @@ -39,7 +39,7 @@ Asynchronously adds a list of documents to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The document you want to add. @@ -47,14 +47,50 @@ Adds a list of documents to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The document you want to add. + + + Asynchronously adds a document to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to add. + + + + Adds a document to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to add. + + + + Asynchronously adds a list of documents to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The documents you want to add. + + + + Adds a list of documents to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The documents you want to add. + Asynchronously returns one document given its id. - + The type representing a Document. The Id of the document you want to get. An optional partition key. @@ -62,7 +98,7 @@ Returns one document given its id. - + The type representing a Document. The Id of the document you want to get. An optional partition key. @@ -70,7 +106,7 @@ Asynchronously returns one document given an expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -78,7 +114,7 @@ Returns one document given an expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -86,7 +122,7 @@ Returns a collection cursor. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -94,7 +130,7 @@ Asynchronously returns true if any of the document of the collection matches the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -102,7 +138,7 @@ Returns true if any of the document of the collection matches the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -110,7 +146,7 @@ Asynchronously returns a list of the documents matching the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -118,7 +154,7 @@ Returns a list of the documents matching the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -126,7 +162,7 @@ Asynchronously counts how many documents match the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -134,29 +170,262 @@ Counts how many documents match the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. + + + Asynchronously returns one document given its id. + + The type representing a Document. + The type of the primary key for a Document. + The Id of the document you want to get. + An optional partition key. + + + + Returns one document given its id. + + The type representing a Document. + The type of the primary key for a Document. + The Id of the document you want to get. + An optional partition key. + + + + Asynchronously returns one document given an expression filter. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns one document given an expression filter. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns a collection cursor. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns true if any of the document of the collection matches the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns true if any of the document of the collection matches the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Asynchronously returns a list of the documents matching the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns a list of the documents matching the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Asynchronously counts how many documents match the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partitionKey + + + + Counts how many documents match the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partitionKey + Asynchronously Updates a document. - + The type representing a Document. The document with the modifications you want to persist. Updates a document. - + The type representing a Document. The document with the modifications you want to persist. + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The document you want to modify. + The update definition for the document. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The document you want to modify. + The update definition for the document. + + + + Asynchronously Updates a document. + + The type representing a Document. + The type of the primary key for a Document. + The document with the modifications you want to persist. + + + + Updates a document. + + The type representing a Document. + The type of the primary key for a Document. + The document with the modifications you want to persist. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to modify. + The update definition for the document. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to modify. + The update definition for the document. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + Asynchronously deletes a document. - + The type representing a Document. The document you want to delete. The number of documents deleted. @@ -164,7 +433,7 @@ Asynchronously deletes a document matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -173,7 +442,7 @@ Deletes a document. - + The type representing a Document. The document you want to delete. The number of documents deleted. @@ -181,7 +450,7 @@ Deletes a document matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -190,7 +459,7 @@ Asynchronously deletes the documents matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -199,7 +468,7 @@ Asynchronously deletes a list of documents. - + The type representing a Document. The list of documents to delete. The number of documents deleted. @@ -207,7 +476,7 @@ Deletes a list of documents. - + The type representing a Document. The list of documents to delete. The number of documents deleted. @@ -215,7 +484,83 @@ Deletes the documents matching the condition of the LINQ expression filter. - + The type representing a Document. + A LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + Deletes a document. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to delete. + The number of documents deleted. + + + + 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. + The document you want to delete. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + Asynchronously deletes a list of documents. + + The type representing a Document. + The type of the primary key for a Document. + The list of documents to delete. + The number of documents deleted. + + + + Deletes a list of documents. + + The type representing a Document. + The type of the primary key for a Document. + The list of documents to delete. + The number of documents deleted. + + + + 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 LINQ expression filter. An optional partition key. The number of documents deleted. @@ -224,8 +569,19 @@ Asynchronously returns a projected document matching the filter condition. - - + The type representing a Document. + The type representing the model you want to project to. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -234,8 +590,19 @@ Returns a projected document matching the filter condition. - - + The type representing a Document. + The type representing the model you want to project to. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -244,8 +611,19 @@ 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. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -254,12 +632,78 @@ 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. The projection expression. An optional partition key. + + + 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. + + The projection expression. + An optional partition key. + + + + Asynchronously returns a paginated list of the documents matching the filter condition. + + The type representing a Document. + + 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. + + + + 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. + + 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. + + + + GetAndUpdateOne with filter + + The type representing a Document. + + + + + + + + GetAndUpdateOne with filter + + The type representing a Document. + The type of the primary key for a Document. + + + + + + + + Groups a collection of documents given a grouping criteria, + and returns a list of projected documents. + + The type representing a Document. + The type of the grouping criteria. + The type of the projected group. + The grouping criteria. + The projected group result. + The partition key of your document, if any. + + The base Repository, it is meant to be inherited from by your custom custom MongoRepository implementation. @@ -299,7 +743,7 @@ Asynchronously adds a document to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The document you want to add. @@ -307,7 +751,7 @@ Adds a document to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The document you want to add. @@ -315,7 +759,7 @@ Asynchronously adds a list of documents to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The documents you want to add. @@ -323,14 +767,50 @@ Adds a list of documents to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. + The documents you want to add. + + + + Asynchronously adds a document to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to add. + + + + Adds a document to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to add. + + + + Asynchronously adds a list of documents to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The documents you want to add. + + + + Adds a list of documents to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. The documents you want to add. Asynchronously returns one document given its id. - + The type representing a Document. The Id of the document you want to get. An optional partition key. @@ -338,7 +818,7 @@ Returns one document given its id. - + The type representing a Document. The Id of the document you want to get. An optional partition key. @@ -346,7 +826,7 @@ Asynchronously returns one document given an expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -354,7 +834,7 @@ Returns one document given an expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -362,7 +842,7 @@ Returns a collection cursor. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -370,7 +850,7 @@ Returns true if any of the document of the collection matches the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -378,7 +858,7 @@ Returns true if any of the document of the collection matches the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -386,7 +866,7 @@ Asynchronously returns a list of the documents matching the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -394,7 +874,7 @@ Returns a list of the documents matching the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -402,7 +882,7 @@ Asynchronously counts how many documents match the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partitionKey @@ -410,7 +890,106 @@ Counts how many documents match the filter condition. - + The type representing a Document. + A LINQ expression filter. + An optional partitionKey + + + + Asynchronously returns one document given its id. + + The type representing a Document. + The type of the primary key for a Document. + The Id of the document you want to get. + An optional partition key. + + + + Returns one document given its id. + + The type representing a Document. + The type of the primary key for a Document. + The Id of the document you want to get. + An optional partition key. + + + + Asynchronously returns one document given an expression filter. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns one document given an expression filter. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns a collection cursor. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns true if any of the document of the collection matches the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns true if any of the document of the collection matches the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Asynchronously returns a list of the documents matching the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns a list of the documents matching the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Asynchronously counts how many documents match the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partitionKey + + + + Counts how many documents match the filter condition. + + The type representing a Document. + The type of the primary key for a Document. A LINQ expression filter. An optional partitionKey @@ -418,21 +997,155 @@ Asynchronously Updates a document. - + The type representing a Document. The document with the modifications you want to persist. Updates a document. - + The type representing a Document. The document with the modifications you want to persist. + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The document you want to modify. + The update definition for the document. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The document you want to modify. + The update definition for the document. + + + + Asynchronously Updates a document. + + The type representing a Document. + The type of the primary key for a Document. + The document with the modifications you want to persist. + + + + Updates a document. + + The type representing a Document. + The type of the primary key for a Document. + The document with the modifications you want to persist. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to modify. + The update definition for the document. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to modify. + The update definition for the document. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + Asynchronously deletes a document. - + The type representing a Document. The document you want to delete. The number of documents deleted. @@ -440,7 +1153,7 @@ Deletes a document. - + The type representing a Document. The document you want to delete. The number of documents deleted. @@ -448,7 +1161,7 @@ Deletes a document matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -457,7 +1170,7 @@ Asynchronously deletes a document matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -466,7 +1179,7 @@ Asynchronously deletes the documents matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -475,7 +1188,7 @@ Asynchronously deletes a list of documents. - + The type representing a Document. The list of documents to delete. The number of documents deleted. @@ -483,7 +1196,7 @@ Deletes a list of documents. - + The type representing a Document. The list of documents to delete. The number of documents deleted. @@ -491,7 +1204,83 @@ Deletes the documents matching the condition of the LINQ expression filter. - + The type representing a Document. + A LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + Deletes a document. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to delete. + The number of documents deleted. + + + + 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. + The document you want to delete. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + Asynchronously deletes a list of documents. + + The type representing a Document. + The type of the primary key for a Document. + The list of documents to delete. + The number of documents deleted. + + + + Deletes a list of documents. + + The type representing a Document. + The type of the primary key for a Document. + The list of documents to delete. + The number of documents deleted. + + + + 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 LINQ expression filter. An optional partition key. The number of documents deleted. @@ -500,8 +1289,19 @@ Asynchronously returns a projected document matching the filter condition. - - + The type representing a Document. + The type representing the model you want to project to. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -510,8 +1310,19 @@ Returns a projected document matching the filter condition. - - + The type representing a Document. + The type representing the model you want to project to. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -520,8 +1331,19 @@ 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. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -530,17 +1352,52 @@ 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. The projection expression. An optional partition key. + + + 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. + The document filter. + The projection expression. + An optional partition key. + + + + Groups a collection of documents given a grouping criteria, + and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + + The type representing a Document. + The type of the grouping criteria. + The type of the projected group. + The grouping criteria. + The projected group result. + The partition key of your document, if any. + + Asynchronously returns a paginated list of the documents matching the filter condition. - + The type representing a Document. + + 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. + + + + 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. The number of documents you want to skip. Default value is 0. The number of documents you want to take. Default value is 50. @@ -550,7 +1407,18 @@ GetAndUpdateOne with filter - + The type representing a Document. + + + + + + + + GetAndUpdateOne with filter + + The type representing a Document. + The type of the primary key for a Document. @@ -584,6 +1452,14 @@ The value of the partition key. + + + Returns a collection for a document type that has a partition key. + + The type representing a Document. + The type of the primary key for a Document. + The value of the partition key. + Drops a collection, use very carefully. @@ -622,23 +1498,29 @@ The version of the schema of the document - + This class represents a basic document that can be stored in MongoDb. Your document must implement this class in order for the MongoDbRepository to handle them. - + - The Guid, which must be decorated with the [BsonId] attribute + The Primary Key, which must be decorated with the [BsonId] attribute if you want the MongoDb C# driver to consider it to be the document ID. - + A version number, to indicate the version of the schema. + + + This class represents a basic document that can be stored in MongoDb. + Your document must implement this class in order for the MongoDbRepository to handle them. + + This class represents a document that can be inserted in a collection that can be partitioned. @@ -705,33 +1587,41 @@ The private GetCollection method - + The type representing a Document. Returns a collection for a document type that has a partition key. - + The type representing a Document. + The value of the partition key. + + + + Returns a collection for a document type that has a partition key. + + The type representing a Document. + The type of the primary key for a Document. The value of the partition key. Drops a collection, use very carefully. - + The type representing a Document. Drops a collection having a partitionkey, use very carefully. - + The type representing a Document. Very naively pluralizes a TDocument type name. - + The type representing a Document. diff --git a/MongoDbGenericRepository/lib/netstandard2.0/MongoDbGenericRepository.dll b/MongoDbGenericRepository/lib/netstandard2.0/MongoDbGenericRepository.dll index 8a408e0..c914cf7 100644 Binary files a/MongoDbGenericRepository/lib/netstandard2.0/MongoDbGenericRepository.dll and b/MongoDbGenericRepository/lib/netstandard2.0/MongoDbGenericRepository.dll differ diff --git a/MongoDbGenericRepository/lib/netstandard2.0/MongoDbGenericRepository.xml b/MongoDbGenericRepository/lib/netstandard2.0/MongoDbGenericRepository.xml index 9afe743..9a99a51 100644 --- a/MongoDbGenericRepository/lib/netstandard2.0/MongoDbGenericRepository.xml +++ b/MongoDbGenericRepository/lib/netstandard2.0/MongoDbGenericRepository.xml @@ -23,7 +23,7 @@ Asynchronously adds a document to the collection. - + The type representing a Document. The document you want to add. @@ -31,7 +31,7 @@ Adds a document to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The document you want to add. @@ -39,7 +39,7 @@ Asynchronously adds a list of documents to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The document you want to add. @@ -47,14 +47,50 @@ Adds a list of documents to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The document you want to add. + + + Asynchronously adds a document to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to add. + + + + Adds a document to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to add. + + + + Asynchronously adds a list of documents to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The documents you want to add. + + + + Adds a list of documents to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The documents you want to add. + Asynchronously returns one document given its id. - + The type representing a Document. The Id of the document you want to get. An optional partition key. @@ -62,7 +98,7 @@ Returns one document given its id. - + The type representing a Document. The Id of the document you want to get. An optional partition key. @@ -70,7 +106,7 @@ Asynchronously returns one document given an expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -78,7 +114,7 @@ Returns one document given an expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -86,7 +122,7 @@ Returns a collection cursor. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -94,7 +130,7 @@ Asynchronously returns true if any of the document of the collection matches the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -102,7 +138,7 @@ Returns true if any of the document of the collection matches the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -110,7 +146,7 @@ Asynchronously returns a list of the documents matching the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -118,7 +154,7 @@ Returns a list of the documents matching the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -126,7 +162,7 @@ Asynchronously counts how many documents match the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -134,29 +170,262 @@ Counts how many documents match the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. + + + Asynchronously returns one document given its id. + + The type representing a Document. + The type of the primary key for a Document. + The Id of the document you want to get. + An optional partition key. + + + + Returns one document given its id. + + The type representing a Document. + The type of the primary key for a Document. + The Id of the document you want to get. + An optional partition key. + + + + Asynchronously returns one document given an expression filter. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns one document given an expression filter. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns a collection cursor. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns true if any of the document of the collection matches the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns true if any of the document of the collection matches the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Asynchronously returns a list of the documents matching the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns a list of the documents matching the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Asynchronously counts how many documents match the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partitionKey + + + + Counts how many documents match the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partitionKey + Asynchronously Updates a document. - + The type representing a Document. The document with the modifications you want to persist. Updates a document. - + The type representing a Document. The document with the modifications you want to persist. + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The document you want to modify. + The update definition for the document. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The document you want to modify. + The update definition for the document. + + + + Asynchronously Updates a document. + + The type representing a Document. + The type of the primary key for a Document. + The document with the modifications you want to persist. + + + + Updates a document. + + The type representing a Document. + The type of the primary key for a Document. + The document with the modifications you want to persist. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to modify. + The update definition for the document. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to modify. + The update definition for the document. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + Asynchronously deletes a document. - + The type representing a Document. The document you want to delete. The number of documents deleted. @@ -164,7 +433,7 @@ Asynchronously deletes a document matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -173,7 +442,7 @@ Deletes a document. - + The type representing a Document. The document you want to delete. The number of documents deleted. @@ -181,7 +450,7 @@ Deletes a document matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -190,7 +459,7 @@ Asynchronously deletes the documents matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -199,7 +468,7 @@ Asynchronously deletes a list of documents. - + The type representing a Document. The list of documents to delete. The number of documents deleted. @@ -207,7 +476,7 @@ Deletes a list of documents. - + The type representing a Document. The list of documents to delete. The number of documents deleted. @@ -215,7 +484,83 @@ Deletes the documents matching the condition of the LINQ expression filter. - + The type representing a Document. + A LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + Deletes a document. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to delete. + The number of documents deleted. + + + + 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. + The document you want to delete. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + Asynchronously deletes a list of documents. + + The type representing a Document. + The type of the primary key for a Document. + The list of documents to delete. + The number of documents deleted. + + + + Deletes a list of documents. + + The type representing a Document. + The type of the primary key for a Document. + The list of documents to delete. + The number of documents deleted. + + + + 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 LINQ expression filter. An optional partition key. The number of documents deleted. @@ -224,8 +569,19 @@ Asynchronously returns a projected document matching the filter condition. - - + The type representing a Document. + The type representing the model you want to project to. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -234,8 +590,19 @@ Returns a projected document matching the filter condition. - - + The type representing a Document. + The type representing the model you want to project to. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -244,8 +611,19 @@ 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. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -254,12 +632,78 @@ 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. The projection expression. An optional partition key. + + + 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. + + The projection expression. + An optional partition key. + + + + Asynchronously returns a paginated list of the documents matching the filter condition. + + The type representing a Document. + + 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. + + + + 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. + + 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. + + + + GetAndUpdateOne with filter + + The type representing a Document. + + + + + + + + GetAndUpdateOne with filter + + The type representing a Document. + The type of the primary key for a Document. + + + + + + + + Groups a collection of documents given a grouping criteria, + and returns a list of projected documents. + + The type representing a Document. + The type of the grouping criteria. + The type of the projected group. + The grouping criteria. + The projected group result. + The partition key of your document, if any. + + The base Repository, it is meant to be inherited from by your custom custom MongoRepository implementation. @@ -299,7 +743,7 @@ Asynchronously adds a document to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The document you want to add. @@ -307,7 +751,7 @@ Adds a document to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The document you want to add. @@ -315,7 +759,7 @@ Asynchronously adds a list of documents to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. The documents you want to add. @@ -323,14 +767,50 @@ Adds a list of documents to the collection. Populates the Id and AddedAtUtc fields if necessary. - + The type representing a Document. + The documents you want to add. + + + + Asynchronously adds a document to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to add. + + + + Adds a document to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to add. + + + + Asynchronously adds a list of documents to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. + The documents you want to add. + + + + Adds a list of documents to the collection. + Populates the Id and AddedAtUtc fields if necessary. + + The type representing a Document. + The type of the primary key for a Document. The documents you want to add. Asynchronously returns one document given its id. - + The type representing a Document. The Id of the document you want to get. An optional partition key. @@ -338,7 +818,7 @@ Returns one document given its id. - + The type representing a Document. The Id of the document you want to get. An optional partition key. @@ -346,7 +826,7 @@ Asynchronously returns one document given an expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -354,7 +834,7 @@ Returns one document given an expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -362,7 +842,7 @@ Returns a collection cursor. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -370,7 +850,7 @@ Returns true if any of the document of the collection matches the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -378,7 +858,7 @@ Returns true if any of the document of the collection matches the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -386,7 +866,7 @@ Asynchronously returns a list of the documents matching the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -394,7 +874,7 @@ Returns a list of the documents matching the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partition key. @@ -402,7 +882,7 @@ Asynchronously counts how many documents match the filter condition. - + The type representing a Document. A LINQ expression filter. An optional partitionKey @@ -410,7 +890,106 @@ Counts how many documents match the filter condition. - + The type representing a Document. + A LINQ expression filter. + An optional partitionKey + + + + Asynchronously returns one document given its id. + + The type representing a Document. + The type of the primary key for a Document. + The Id of the document you want to get. + An optional partition key. + + + + Returns one document given its id. + + The type representing a Document. + The type of the primary key for a Document. + The Id of the document you want to get. + An optional partition key. + + + + Asynchronously returns one document given an expression filter. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns one document given an expression filter. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns a collection cursor. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns true if any of the document of the collection matches the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns true if any of the document of the collection matches the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Asynchronously returns a list of the documents matching the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Returns a list of the documents matching the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partition key. + + + + Asynchronously counts how many documents match the filter condition. + + The type representing a Document. + The type of the primary key for a Document. + A LINQ expression filter. + An optional partitionKey + + + + Counts how many documents match the filter condition. + + The type representing a Document. + The type of the primary key for a Document. A LINQ expression filter. An optional partitionKey @@ -418,21 +997,155 @@ Asynchronously Updates a document. - + The type representing a Document. The document with the modifications you want to persist. Updates a document. - + The type representing a Document. The document with the modifications you want to persist. + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The document you want to modify. + The update definition for the document. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The document you want to modify. + The update definition for the document. + + + + Asynchronously Updates a document. + + The type representing a Document. + The type of the primary key for a Document. + The document with the modifications you want to persist. + + + + Updates a document. + + The type representing a Document. + The type of the primary key for a Document. + The document with the modifications you want to persist. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to modify. + The update definition for the document. + + + + Takes a document you want to modify and applies the update you have defined in MongoDb. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to modify. + The update definition for the document. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document you want to modify. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + + + + Updates the property field with the given value update a property field in entities. + + The type representing a Document. + The type of the primary key for a Document. + The type of the field. + The document filter. + The field selector. + The new value of the property field. + Asynchronously deletes a document. - + The type representing a Document. The document you want to delete. The number of documents deleted. @@ -440,7 +1153,7 @@ Deletes a document. - + The type representing a Document. The document you want to delete. The number of documents deleted. @@ -448,7 +1161,7 @@ Deletes a document matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -457,7 +1170,7 @@ Asynchronously deletes a document matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -466,7 +1179,7 @@ Asynchronously deletes the documents matching the condition of the LINQ expression filter. - + The type representing a Document. A LINQ expression filter. An optional partition key. The number of documents deleted. @@ -475,7 +1188,7 @@ Asynchronously deletes a list of documents. - + The type representing a Document. The list of documents to delete. The number of documents deleted. @@ -483,7 +1196,7 @@ Deletes a list of documents. - + The type representing a Document. The list of documents to delete. The number of documents deleted. @@ -491,7 +1204,83 @@ Deletes the documents matching the condition of the LINQ expression filter. - + The type representing a Document. + A LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + Deletes a document. + + The type representing a Document. + The type of the primary key for a Document. + The document you want to delete. + The number of documents deleted. + + + + 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. + The document you want to delete. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + 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 LINQ expression filter. + An optional partition key. + The number of documents deleted. + + + + Asynchronously deletes a list of documents. + + The type representing a Document. + The type of the primary key for a Document. + The list of documents to delete. + The number of documents deleted. + + + + Deletes a list of documents. + + The type representing a Document. + The type of the primary key for a Document. + The list of documents to delete. + The number of documents deleted. + + + + 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 LINQ expression filter. An optional partition key. The number of documents deleted. @@ -500,8 +1289,19 @@ Asynchronously returns a projected document matching the filter condition. - - + The type representing a Document. + The type representing the model you want to project to. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -510,8 +1310,19 @@ Returns a projected document matching the filter condition. - - + The type representing a Document. + The type representing the model you want to project to. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -520,8 +1331,19 @@ 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. + + The projection expression. + An optional partition key. + + + + 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. The projection expression. An optional partition key. @@ -530,17 +1352,52 @@ 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. The projection expression. An optional partition key. + + + 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. + The document filter. + The projection expression. + An optional partition key. + + + + Groups a collection of documents given a grouping criteria, + and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + + The type representing a Document. + The type of the grouping criteria. + The type of the projected group. + The grouping criteria. + The projected group result. + The partition key of your document, if any. + + Asynchronously returns a paginated list of the documents matching the filter condition. - + The type representing a Document. + + 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. + + + + 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. The number of documents you want to skip. Default value is 0. The number of documents you want to take. Default value is 50. @@ -550,7 +1407,18 @@ GetAndUpdateOne with filter - + The type representing a Document. + + + + + + + + GetAndUpdateOne with filter + + The type representing a Document. + The type of the primary key for a Document. @@ -584,6 +1452,14 @@ The value of the partition key. + + + Returns a collection for a document type that has a partition key. + + The type representing a Document. + The type of the primary key for a Document. + The value of the partition key. + Drops a collection, use very carefully. @@ -622,23 +1498,29 @@ The version of the schema of the document - + This class represents a basic document that can be stored in MongoDb. Your document must implement this class in order for the MongoDbRepository to handle them. - + - The Guid, which must be decorated with the [BsonId] attribute + The Primary Key, which must be decorated with the [BsonId] attribute if you want the MongoDb C# driver to consider it to be the document ID. - + A version number, to indicate the version of the schema. + + + This class represents a basic document that can be stored in MongoDb. + Your document must implement this class in order for the MongoDbRepository to handle them. + + This class represents a document that can be inserted in a collection that can be partitioned. @@ -705,33 +1587,41 @@ The private GetCollection method - + The type representing a Document. Returns a collection for a document type that has a partition key. - + The type representing a Document. + The value of the partition key. + + + + Returns a collection for a document type that has a partition key. + + The type representing a Document. + The type of the primary key for a Document. The value of the partition key. Drops a collection, use very carefully. - + The type representing a Document. Drops a collection having a partitionkey, use very carefully. - + The type representing a Document. Very naively pluralizes a TDocument type name. - + The type representing a Document.