using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; using MongoDB.Driver.Linq; using MongoDbGenericRepository.DataAccess.Base; using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository.DataAccess.Read { public interface IMongoDbReader : IDataAccessBase { /// /// Asynchronously returns a projected document matching the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// The type representing the model you want to project to. /// A LINQ expression filter. /// The projection expression. /// An optional partition key. /// An optional cancellation Token. Task ProjectOneAsync( Expression> filter, Expression> projection, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable where TProjection : class; /// /// Returns a projected document matching the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// The type representing the model you want to project to. /// A LINQ expression filter. /// 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 of the primary key for a Document. /// The type representing the model you want to project to. /// A LINQ expression filter. /// The projection expression. /// An optional partition key. /// An optional cancellation Token. Task> ProjectManyAsync( Expression> filter, Expression> projection, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable where TProjection : class; /// /// Asynchronously returns a list of projected documents matching the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// The type representing the model you want to project to. /// The document filter. /// 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; /// /// 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 primary key for 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 TKey : IEquatable 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 primary key for a Document. /// The type of the grouping criteria. /// The type of the projected group. /// A LINQ expression filter. /// 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 TKey : IEquatable 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 primary key for a Document. /// The type of the grouping criteria. /// The type of the projected group. /// A LINQ expression filter. /// The grouping criteria. /// The projected group result. /// The partition key of your document, if any. /// An optional cancellation Token. Task> GroupByAsync( Expression> filter, Expression> selector, Expression, TProjection>> projection, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable where TProjection : class, new(); /// /// Asynchronously returns a paginated list of the documents matching the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// The property selector. /// Order of the sorting. /// The number of documents you want to skip. Default value is 0. /// The number of documents you want to take. Default value is 50. /// An optional partition key. /// An optional cancellation Token. Task> GetSortedPaginatedAsync( Expression> filter, Expression> sortSelector, bool ascending = true, int skipNumber = 0, int takeNumber = 50, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; /// /// Asynchronously returns a paginated list of the documents matching the filter condition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// The sort definition. /// The number of documents you want to skip. Default value is 0. /// The number of documents you want to take. Default value is 50. /// An optional partition key. /// An optional cancellation Token. Task> GetSortedPaginatedAsync( Expression> filter, SortDefinition sortDefinition, int skipNumber = 0, int takeNumber = 50, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; /// /// 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. /// An optional cancellation Token. Task GetByIdAsync(TKey id, string partitionKey = null, CancellationToken cancellationToken = default) 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 filter definition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A mongodb filter definition. /// A mongodb filter option. /// An optional partition key. /// An optional cancellation Token. Task GetOneAsync(FilterDefinition condition, FindOptions findOption = null, string partitionKey = null, CancellationToken cancellationToken = default) 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. /// An optional cancellation Token. Task GetOneAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; /// /// Returns one document given filter definition. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A mongodb filter definition. /// A mongodb filter option. /// An optional partition key. TDocument GetOne(FilterDefinition condition, FindOptions findOption = null, 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 mongodb filter definition. /// A mongodb counting option. /// An optional partition key. /// An optional cancellation Token. Task AnyAsync(FilterDefinition condition, CountOptions countOption = null, string partitionKey = null, CancellationToken cancellationToken = default) 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. /// An optional cancellation Token. Task AnyAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) 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 mongodb filter definition. /// A mongodb counting option. /// An optional partition key. bool Any(FilterDefinition condition, CountOptions countOption = null, 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 mongodb filter definition. /// A mongodb filter option. /// An optional partition key. /// An optional cancellation Token. Task> GetAllAsync(FilterDefinition condition, FindOptions findOption = null, string partitionKey = null, CancellationToken cancellationToken = default) 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. /// An optional cancellation Token. Task> GetAllAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) 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 mongodb filter definition. /// A mongodb filter option. /// An optional partition key. List GetAll(FilterDefinition condition, FindOptions findOption = null, 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 mongodb filter definition. /// A mongodb counting option. /// An optional partitionKey /// An optional cancellation Token. Task CountAsync(FilterDefinition condition, CountOptions countOption = null, string partitionKey = null, CancellationToken cancellationToken = default) 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 /// An optional cancellation Token. Task CountAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) 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 mongodb filter definition. /// A mongodb counting option. /// An optional partitionKey long Count(FilterDefinition condition, CountOptions countOption = null, 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; /// /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. /// /// The document type. /// The type of the primary key. /// A LINQ expression filter. /// A property selector to order by descending. /// An optional partitionKey. /// An optional cancellation Token. Task GetByMaxAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; /// /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. /// /// The document type. /// The type of the primary key. /// A LINQ expression filter. /// A property selector to order by descending. /// An optional partitionKey. TDocument GetByMax(Expression> filter, Expression> maxValueSelector, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable; /// /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. /// /// The document type. /// The type of the primary key. /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partitionKey. /// An optional cancellation Token. Task GetByMinAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; /// /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. /// /// The document type. /// The type of the primary key. /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partitionKey. TDocument GetByMin(Expression> filter, Expression> minValueSelector, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable; /// /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// /// The document type. /// The type of the primary key. /// The type of the field for which you want the maximum value. /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partitionKey. /// An optional cancellation Token. Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; /// /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// /// The document type. /// The type of the primary key. /// The type of the value used to order the query. /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partitionKey. TValue GetMaxValue(Expression> filter, Expression> maxValueSelector, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable; /// /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// /// The document type. /// The type of the primary key. /// The type of the value used to order the query. /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partition key. /// An optional cancellation Token. Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; /// /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// /// The document type. /// The type of the primary key. /// The type of the value used to order the query. /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partition key. TValue GetMinValue(Expression> filter, Expression> minValueSelector, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable; /// /// Sums the values of a selected field for a given filtered collection of documents. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// The field you want to sum. /// The partition key of your document, if any. /// An optional cancellation Token. Task SumByAsync(Expression> filter, Expression> selector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; /// /// Sums the values of a selected field for a given filtered collection of documents. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// The field you want to sum. /// The partition key of your document, if any. /// An optional cancellation Token. Task SumByAsync(Expression> filter, Expression> selector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; /// /// Sums the values of a selected field for a given filtered collection of documents. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// The field you want to sum. /// The partition key of your document, if any. int SumBy(Expression> filter, Expression> selector, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable; /// /// Sums the values of a selected field for a given filtered collection of documents. /// /// The type representing a Document. /// The type of the primary key for a Document. /// A LINQ expression filter. /// The field you want to sum. /// The partition key of your document, if any. decimal SumBy(Expression> filter, Expression> selector, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable; /// /// Gets a IMongoQueryable for a potentially partitioned document type and a filter. /// /// The document type. /// The type of the primary key. /// The filter definition. /// The collection partition key. /// IMongoQueryable GetQuery(Expression> filter, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable; /// /// Gets a collections for a potentially partitioned document type. /// /// The document type. /// The type of the primary key. /// The document. /// IMongoCollection HandlePartitioned(TDocument document) where TDocument : IDocument where TKey : IEquatable; /// /// Gets a collections for a potentially partitioned document type. /// /// The document type. /// The type of the primary key. /// The collection partition key. /// IMongoCollection HandlePartitioned(string partitionKey) where TDocument : IDocument where TKey : IEquatable; /// /// Gets a collections for the type TDocument with a partition key. /// /// The document type. /// The type of the primary key. /// The collection partition key. /// IMongoCollection GetCollection(string partitionKey = null) where TDocument : IDocument where TKey : IEquatable; } }