Add read operation support for filter definition
This commit is contained in:
@@ -57,6 +57,39 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
return HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously returns one document given filter definition.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="condition">A mongodb filter definition.</param>
|
||||
/// <param name="findOption">A mongodb filter option.</param>
|
||||
/// <param name="partitionKey">An optional partition key.</param>
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual Task<TDocument> GetOneAsync<TDocument, TKey>(FilterDefinition<TDocument> condition, FindOptions findOption = null,
|
||||
string partitionKey = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
return HandlePartitioned<TDocument, TKey>(partitionKey).Find(condition, findOption).FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns one document given filter definition.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="condition">A mongodb filter definition.</param>
|
||||
/// <param name="findOption">A mongodb filter option.</param>
|
||||
/// <param name="partitionKey">An optional partition key.</param>
|
||||
public virtual TDocument GetOne<TDocument, TKey>(FilterDefinition<TDocument> condition, FindOptions findOption = null, string partitionKey = null)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
return HandlePartitioned<TDocument, TKey>(partitionKey).Find(condition, findOption).FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously returns one document given an expression filter.
|
||||
/// </summary>
|
||||
@@ -100,6 +133,41 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
return HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if any of the document of the collection matches the filter condition.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="condition">A mongodb filter definition.</param>
|
||||
/// <param name="countOption">A mongodb counting option.</param>
|
||||
/// <param name="partitionKey">An optional partition key.</param>
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual async Task<bool> AnyAsync<TDocument, TKey>(FilterDefinition<TDocument> condition, CountOptions countOption = null, string partitionKey = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
var count = await HandlePartitioned<TDocument, TKey>(partitionKey).CountDocumentsAsync(condition, countOption, cancellationToken);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if any of the document of the collection matches the filter condition.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="condition">A mongodb filter definition.</param>
|
||||
/// <param name="countOption">A mongodb counting option.</param>
|
||||
/// <param name="partitionKey">An optional partition key.</param>
|
||||
public virtual bool Any<TDocument, TKey>(FilterDefinition<TDocument> condition, CountOptions countOption = null,
|
||||
string partitionKey = null)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
var count = HandlePartitioned<TDocument, TKey>(partitionKey).CountDocuments(condition, countOption);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if any of the document of the collection matches the filter condition.
|
||||
/// </summary>
|
||||
@@ -131,6 +199,39 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
return (count > 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously returns a list of the documents matching the filter condition.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="condition">A mongodb filter definition.</param>
|
||||
/// <param name="findOption">A mongodb filter option.</param>
|
||||
/// <param name="partitionKey">An optional partition key.</param>
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual Task<List<TDocument>> GetAllAsync<TDocument, TKey>(FilterDefinition<TDocument> condition,
|
||||
FindOptions findOption = null, string partitionKey = null, CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
return HandlePartitioned<TDocument, TKey>(partitionKey).Find(condition, findOption).ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of the documents matching the filter condition.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="condition">A mongodb filter definition.</param>
|
||||
/// <param name="findOption">A mongodb filter option.</param>
|
||||
/// <param name="partitionKey">An optional partition key.</param>
|
||||
public virtual List<TDocument> GetAll<TDocument, TKey>(FilterDefinition<TDocument> condition, FindOptions findOption = null,
|
||||
string partitionKey = null)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
return HandlePartitioned<TDocument, TKey>(partitionKey).Find(condition, findOption).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously returns a list of the documents matching the filter condition.
|
||||
/// </summary>
|
||||
@@ -160,6 +261,39 @@ namespace MongoDbGenericRepository.DataAccess.Read
|
||||
return HandlePartitioned<TDocument, TKey>(partitionKey).Find(filter).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously counts how many documents match the filter condition.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="condition">A mongodb filter definition.</param>
|
||||
/// <param name="countOption">A mongodb counting option.</param>
|
||||
/// <param name="partitionKey">An optional partitionKey</param>
|
||||
/// <param name="cancellationToken">An optional cancellation Token.</param>
|
||||
public virtual Task<long> CountAsync<TDocument, TKey>(FilterDefinition<TDocument> condition, CountOptions countOption = null,
|
||||
string partitionKey = null, CancellationToken cancellationToken = default)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
return HandlePartitioned<TDocument, TKey>(partitionKey).CountDocumentsAsync(condition, countOption, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts how many documents match the filter condition.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="condition">A mongodb filter definition.</param>
|
||||
/// <param name="countOption">A mongodb counting option.</param>
|
||||
/// <param name="partitionKey">An optional partitionKey</param>
|
||||
public virtual long Count<TDocument, TKey>(FilterDefinition<TDocument> condition, CountOptions countOption = null,
|
||||
string partitionKey = null)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
return HandlePartitioned<TDocument, TKey>(partitionKey).CountDocuments(condition, countOption);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously counts how many documents match the filter condition.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user