Compare commits
4 Commits
alex/UpdateMany
...
1.4.7
| Author | SHA1 | Date | |
|---|---|---|---|
| 71b64c84a0 | |||
| 5f6e015bf2 | |||
| 6d8e358ccc | |||
| 76a1aab671 |
@@ -8,6 +8,7 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.1.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.1.2" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.12.0" />
|
||||
<PackageReference Include="MongoDbGenericRepository" Version="1.4.6" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.console" Version="2.4.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
@@ -17,10 +18,6 @@
|
||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta4-build3742" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MongoDbGenericRepository\MongoDbGenericRepository.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Configuration">
|
||||
<HintPath>..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Configuration.dll</HintPath>
|
||||
|
||||
@@ -796,7 +796,7 @@ namespace CoreIntegrationTests.Infrastructure
|
||||
|
||||
#region Index Management
|
||||
|
||||
static SemaphoreSlim textIndexSemaphore = new SemaphoreSlim(1, 1);
|
||||
static readonly SemaphoreSlim textIndexSemaphore = new SemaphoreSlim(1, 1);
|
||||
|
||||
[Fact]
|
||||
public async Task CreateTextIndexNoOptionAsync()
|
||||
|
||||
@@ -2,10 +2,15 @@
|
||||
using MongoDbGenericRepository.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MongoDbGenericRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// The IBaseMongoRepository_Create interface to expose document creation functionality
|
||||
/// with document having an Id of type Guid.
|
||||
/// </summary>
|
||||
public interface IBaseMongoRepository_Create : IBaseMongoRepository_Create<Guid>
|
||||
{
|
||||
/// <summary>
|
||||
@@ -15,7 +20,8 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="document">The document you want to add.</param>
|
||||
Task AddOneAsync<TDocument, TKey>(TDocument document)
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
Task AddOneAsync<TDocument, TKey>(TDocument document, CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
|
||||
@@ -37,7 +43,8 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="documents">The documents you want to add.</param>
|
||||
Task AddManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents)
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
Task AddManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents, CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
|
||||
@@ -61,6 +68,10 @@ namespace MongoDbGenericRepository
|
||||
{
|
||||
private readonly object _initLock = new object();
|
||||
private MongoDbCreator _mongoDbCreator;
|
||||
|
||||
/// <summary>
|
||||
/// The MongoDbCreator field.
|
||||
/// </summary>
|
||||
protected virtual MongoDbCreator MongoDbCreator
|
||||
{
|
||||
get
|
||||
@@ -87,11 +98,12 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="document">The document you want to add.</param>
|
||||
public virtual async Task AddOneAsync<TDocument, TKey>(TDocument document)
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task AddOneAsync<TDocument, TKey>(TDocument document, CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
await MongoDbCreator.AddOneAsync<TDocument, TKey>(document);
|
||||
await MongoDbCreator.AddOneAsync<TDocument, TKey>(document, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -100,10 +112,11 @@ namespace MongoDbGenericRepository
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <param name="document">The document you want to add.</param>
|
||||
public virtual async Task AddOneAsync<TDocument>(TDocument document)
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task AddOneAsync<TDocument>(TDocument document, CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<Guid>
|
||||
{
|
||||
await MongoDbCreator.AddOneAsync<TDocument, Guid>(document);
|
||||
await MongoDbCreator.AddOneAsync<TDocument, Guid>(document, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -138,11 +151,12 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="documents">The documents you want to add.</param>
|
||||
public virtual async Task AddManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents)
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task AddManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents, CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
await MongoDbCreator.AddManyAsync<TDocument, TKey>(documents);
|
||||
await MongoDbCreator.AddManyAsync<TDocument, TKey>(documents, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -151,10 +165,11 @@ namespace MongoDbGenericRepository
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <param name="documents">The documents you want to add.</param>
|
||||
public virtual async Task AddManyAsync<TDocument>(IEnumerable<TDocument> documents)
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task AddManyAsync<TDocument>(IEnumerable<TDocument> documents, CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<Guid>
|
||||
{
|
||||
await MongoDbCreator.AddManyAsync<TDocument, Guid>(documents);
|
||||
await MongoDbCreator.AddManyAsync<TDocument, Guid>(documents, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -28,6 +28,14 @@ namespace MongoDbGenericRepository.DataAccess.Base
|
||||
|
||||
#region Utility Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets a IMongoQueryable for a potentially partitioned document type and a filter.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The document type.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
||||
/// <param name="filter">The filter definition.</param>
|
||||
/// <param name="partitionKey">The collection partition key.</param>
|
||||
/// <returns></returns>
|
||||
public virtual IMongoQueryable<TDocument> GetQuery<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
|
||||
@@ -6,12 +6,20 @@ using MongoDbGenericRepository.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MongoDbGenericRepository.DataAccess.Create
|
||||
{
|
||||
/// <summary>
|
||||
/// A class to insert MongoDb document.
|
||||
/// </summary>
|
||||
public class MongoDbCreator : DataAccessBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The construct of the MongoDbCreator class.
|
||||
/// </summary>
|
||||
/// <param name="mongoDbContext">A <see cref="IMongoDbContext"/> instance.</param>
|
||||
public MongoDbCreator(IMongoDbContext mongoDbContext) : base(mongoDbContext)
|
||||
{
|
||||
}
|
||||
@@ -25,12 +33,13 @@ namespace MongoDbGenericRepository.DataAccess.Create
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="document">The document you want to add.</param>
|
||||
public virtual async Task AddOneAsync<TDocument, TKey>(TDocument document)
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task AddOneAsync<TDocument, TKey>(TDocument document, CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
FormatDocument<TDocument, TKey>(document);
|
||||
await HandlePartitioned<TDocument, TKey>(document).InsertOneAsync(document);
|
||||
await HandlePartitioned<TDocument, TKey>(document).InsertOneAsync(document, null, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -55,7 +64,8 @@ namespace MongoDbGenericRepository.DataAccess.Create
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="documents">The documents you want to add.</param>
|
||||
public virtual async Task AddManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents)
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task AddManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents, CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
@@ -72,12 +82,12 @@ namespace MongoDbGenericRepository.DataAccess.Create
|
||||
{
|
||||
foreach (var group in documents.GroupBy(e => ((IPartitionedDocument)e).PartitionKey))
|
||||
{
|
||||
await HandlePartitioned<TDocument, TKey>(group.FirstOrDefault()).InsertManyAsync(group.ToList());
|
||||
await HandlePartitioned<TDocument, TKey>(group.FirstOrDefault()).InsertManyAsync(group.ToList(), null, cancellationToken);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await GetCollection<TDocument, TKey>().InsertManyAsync(documents.ToList());
|
||||
await GetCollection<TDocument, TKey>().InsertManyAsync(documents.ToList(), null, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,15 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MongoDbGenericRepository.DataAccess.Read
|
||||
{
|
||||
/// <summary>
|
||||
/// A class to read MongoDb document.
|
||||
/// </summary>
|
||||
public partial class MongoDbReader : DataAccessBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The construct of the MongoDbReader class.
|
||||
/// </summary>
|
||||
/// <param name="mongoDbContext">A <see cref="IMongoDbContext"/> instance.</param>
|
||||
public MongoDbReader(IMongoDbContext mongoDbContext) : base(mongoDbContext)
|
||||
{
|
||||
}
|
||||
@@ -193,7 +200,7 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
||||
/// <param name="filter">A LINQ expression filter.</param>
|
||||
/// <param name="maxValueSelector">A property selector to order by descending.</param>
|
||||
/// <param name="partitionKey">An optional partitionKey.</param
|
||||
/// <param name="partitionKey">An optional partitionKey.</param>
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public async virtual Task<TDocument> GetByMaxAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, object>> maxValueSelector, string partitionKey = null, CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using MongoDbGenericRepository.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MongoDbGenericRepository
|
||||
@@ -18,7 +19,8 @@ namespace MongoDbGenericRepository
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <param name="document">The document you want to add.</param>
|
||||
Task AddOneAsync<TDocument>(TDocument document) where TDocument : IDocument<TKey>;
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
Task AddOneAsync<TDocument>(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument<TKey>;
|
||||
|
||||
/// <summary>
|
||||
/// Adds a document to the collection.
|
||||
@@ -34,7 +36,8 @@ namespace MongoDbGenericRepository
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <param name="documents">The documents you want to add.</param>
|
||||
Task AddManyAsync<TDocument>(IEnumerable<TDocument> documents) where TDocument : IDocument<TKey>;
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
Task AddManyAsync<TDocument>(IEnumerable<TDocument> documents, CancellationToken cancellationToken = default) where TDocument : IDocument<TKey>;
|
||||
|
||||
/// <summary>
|
||||
/// Adds a list of documents to the collection.
|
||||
@@ -81,9 +84,10 @@ namespace MongoDbGenericRepository
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <param name="document">The document you want to add.</param>
|
||||
public virtual async Task AddOneAsync<TDocument>(TDocument document) where TDocument : IDocument<TKey>
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task AddOneAsync<TDocument>(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument<TKey>
|
||||
{
|
||||
await MongoDbCreator.AddOneAsync<TDocument, TKey>(document);
|
||||
await MongoDbCreator.AddOneAsync<TDocument, TKey>(document, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -103,9 +107,10 @@ namespace MongoDbGenericRepository
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <param name="documents">The documents you want to add.</param>
|
||||
public virtual async Task AddManyAsync<TDocument>(IEnumerable<TDocument> documents) where TDocument : IDocument<TKey>
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task AddManyAsync<TDocument>(IEnumerable<TDocument> documents, CancellationToken cancellationToken = default) where TDocument : IDocument<TKey>
|
||||
{
|
||||
await MongoDbCreator.AddManyAsync<TDocument, TKey>(documents);
|
||||
await MongoDbCreator.AddManyAsync<TDocument, TKey>(documents, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<PackageProjectUrl>http://www.opensource.org/licenses/mit-license.php</PackageProjectUrl>
|
||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
||||
<PackageReleaseNotes>Release notes are at https://github.com/alexandre-spieser/mongodb-generic-repository/releases </PackageReleaseNotes>
|
||||
<Copyright>Copyright 2020 (c) Alexandre Spieser. All rights reserved.</Copyright>
|
||||
<Copyright>Copyright 2021 (c) Alexandre Spieser. All rights reserved.</Copyright>
|
||||
<PackageTags>MongoDb Repository Generic NoSql</PackageTags>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Version>1.4.6</Version>
|
||||
|
||||
Reference in New Issue
Block a user