/// <summary> /// Asynchronously returns a list of projected 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> /// <typeparam name="TProjection">The type representing the model you want to project to.</typeparam> /// <param name="filter">The document filter.</param> /// <param name="projection">The projection expression.</param> /// <param name="partitionKey">An optional partition key.</param> public virtual List <TProjection> ProjectMany <TDocument, TProjection, TKey>(Expression <Func <TDocument, bool> > filter, Expression <Func <TDocument, TProjection> > projection, string partitionKey = null) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> where TProjection : class { return(MongoDbReader.ProjectMany <TDocument, TProjection, TKey>(filter, projection, partitionKey)); }
public EventStoreSubscription( DatabaseContext databaseContext, IConnection rabbitMqConnection) { _mongoDbReader = new MongoDbReader <T>(databaseContext); _rabbitMqSubscriber = new RabbitMqSubscriber(rabbitMqConnection); }
/// <summary> /// Sums the values of a selected field for a given filtered collection of documents. /// </summary> /// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key.</typeparam> /// <param name="filter">A LINQ expression filter.</param> /// <param name="selector">The field you want to sum.</param> /// <param name="partitionKey">The partition key of your document, if any.</param> public virtual async Task <int> SumByAsync <TDocument, TKey>(Expression <Func <TDocument, bool> > filter, Expression <Func <TDocument, int> > selector, string partitionKey = null) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> { return(await MongoDbReader.SumByAsync <TDocument, TKey>(filter, selector, partitionKey)); }
/// <summary> /// Sums the values of a selected field for a given filtered collection of documents. /// </summary> /// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key.</typeparam> /// <param name="filter">A LINQ expression filter.</param> /// <param name="selector">The field you want to sum.</param> /// <param name="partitionKey">The partition key of your document, if any.</param> public virtual decimal SumBy <TDocument, TKey>(Expression <Func <TDocument, bool> > filter, Expression <Func <TDocument, decimal> > selector, string partitionKey = null) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> { return(MongoDbReader.SumBy <TDocument, TKey>(filter, selector, partitionKey)); }
/// <summary> /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. /// </summary> /// <typeparam name="TDocument">The document type.</typeparam> /// <typeparam name="TKey">The type of the primary key.</typeparam> /// <param name="filter">A LINQ expression filter.</param> /// <param name="minValueSelector">A property selector for the minimum value you are looking for.</param> /// <param name="partitionKey">An optional partitionKey.</param> /// <param name="cancellationToken">An optional cancellation Token.</param> public async virtual Task <TDocument> GetByMinAsync <TDocument, TKey>(Expression <Func <TDocument, bool> > filter, Expression <Func <TDocument, object> > minValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> { return(await MongoDbReader.GetByMinAsync <TDocument, TKey>(filter, minValueSelector, partitionKey, cancellationToken)); }
/// <summary> /// Asynchronously returns a list of projected 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> /// <typeparam name="TProjection">The type representing the model you want to project to.</typeparam> /// <param name="filter">A LINQ expression filter.</param> /// <param name="projection">The projection expression.</param> /// <param name="partitionKey">An optional partition key.</param> /// <param name="cancellationToken">An optional cancellation Token.</param> public virtual async Task <List <TProjection> > ProjectManyAsync <TDocument, TProjection, TKey>( Expression <Func <TDocument, bool> > filter, Expression <Func <TDocument, TProjection> > projection, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> where TProjection : class { return(await MongoDbReader.ProjectManyAsync <TDocument, TProjection, TKey>(filter, projection, partitionKey, cancellationToken)); }
/// <summary> /// 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. /// </summary> /// <typeparam name="TDocument">The type representing a Document.</typeparam> /// <typeparam name="TKey">The type of the primary key for a Document.</typeparam> /// <typeparam name="TGroupKey">The type of the grouping criteria.</typeparam> /// <typeparam name="TProjection">The type of the projected group.</typeparam> /// <param name="groupingCriteria">The grouping criteria.</param> /// <param name="groupProjection">The projected group result.</param> /// <param name="partitionKey">The partition key of your document, if any.</param> public virtual List <TProjection> GroupBy <TDocument, TGroupKey, TProjection, TKey>( Expression <Func <TDocument, TGroupKey> > groupingCriteria, Expression <Func <IGrouping <TGroupKey, TDocument>, TProjection> > groupProjection, string partitionKey = null) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> where TProjection : class, new() { return(MongoDbReader.GroupBy <TDocument, TGroupKey, TProjection, TKey>(groupingCriteria, groupProjection, partitionKey)); }
/// <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="filter">A LINQ expression filter.</param> /// <param name="partitionKey">An optional partitionKey</param> public async virtual Task <long> CountAsync <TDocument, TKey>(Expression <Func <TDocument, bool> > filter, string partitionKey = null) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> { return(await MongoDbReader.CountAsync <TDocument, TKey>(filter, partitionKey)); }
/// <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 TDocument GetOne <TDocument, TKey>(FilterDefinition <TDocument> condition, FindOptions findOption = null, string partitionKey = null) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> { return(MongoDbReader.GetOne <TDocument, TKey>(condition, findOption, partitionKey)); }
/// <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 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(MongoDbReader.GetOneAsync <TDocument, TKey>(condition, findOption, partitionKey, 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 long Count <TDocument, TKey>(FilterDefinition <TDocument> condition, CountOptions countOption = null, string partitionKey = null) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> { return(MongoDbReader.Count <TDocument, TKey>(condition, countOption, partitionKey)); }
/// <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="filter">A LINQ expression filter.</param> /// <param name="partitionKey">An optional partition key.</param> /// <param name="cancellationToken">An optional cancellation Token.</param> public async virtual Task <bool> AnyAsync <TDocument, TKey>(Expression <Func <TDocument, bool> > filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> { return(await MongoDbReader.AnyAsync <TDocument, TKey>(filter, partitionKey, cancellationToken)); }
protected void SetupMongoDbContext(IMongoDbContext mongoDbContext) { MongoDbContext = MongoDbContext ?? mongoDbContext; MongoDbReader = MongoDbReader ?? new MongoDbReader(MongoDbContext); }
/// <summary> /// Returns one document given its id. /// </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="id">The Id of the document you want to get.</param> /// <param name="partitionKey">An optional partition key.</param> public virtual TDocument GetById <TDocument, TKey>(TKey id, string partitionKey = null) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> { return(MongoDbReader.GetById <TDocument, TKey>(id, partitionKey)); }
/// <summary> /// Gets a collections for a potentially partitioned document type. /// </summary> /// <typeparam name="TDocument">The document type.</typeparam> /// <param name="document">The document.</param> /// <returns></returns> public virtual IMongoCollection <TDocument> HandlePartitioned <TDocument>(TDocument document) where TDocument : IDocument <Guid> { return(MongoDbReader.HandlePartitioned <TDocument, Guid>(document)); }
/// <summary> /// Asynchronously returns one document given its id. /// </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="id">The Id of the document you want to get.</param> /// <param name="partitionKey">An optional partition key.</param> public async virtual Task <TDocument> GetByIdAsync <TDocument, TKey>(TKey id, string partitionKey = null) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> { return(await MongoDbReader.GetByIdAsync <TDocument, TKey>(id, partitionKey)); }
/// <summary> /// Asynchronously returns one document given its id. /// </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="id">The Id of the document you want to get.</param> /// <param name="partitionKey">An optional partition key.</param> /// <param name="cancellationToken">An optional cancellation Token.</param> public async virtual Task <TDocument> GetByIdAsync <TDocument, TKey>(TKey id, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> { return(await MongoDbReader.GetByIdAsync <TDocument, TKey>(id, partitionKey, cancellationToken)); }
/// <summary> /// Gets a collections for a potentially partitioned document type. /// </summary> /// <typeparam name="TDocument">The document type.</typeparam> /// <typeparam name="TKey">The type of the primary key.</typeparam> /// <param name="document">The document.</param> /// <returns></returns> public virtual IMongoCollection <TDocument> HandlePartitioned <TDocument, TKey>(TDocument document) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> { return(MongoDbReader.HandlePartitioned <TDocument, TKey>(document)); }
/// <summary> /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. /// </summary> /// <typeparam name="TDocument">The document type.</typeparam> /// <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> public virtual TDocument GetByMax <TDocument, TKey>(Expression <Func <TDocument, bool> > filter, Expression <Func <TDocument, object> > maxValueSelector, string partitionKey = null) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> { return(MongoDbReader.GetByMax <TDocument, TKey>(filter, maxValueSelector, partitionKey)); }
/// <summary> /// Gets a collections for the type TDocument with a partition key. /// </summary> /// <typeparam name="TDocument">The document type.</typeparam> /// <typeparam name="TKey">The type of the primary key.</typeparam> /// <param name="partitionKey">The collection partition key.</param> /// <returns></returns> public virtual IMongoCollection <TDocument> GetCollection <TDocument, TKey>(string partitionKey = null) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> { return(MongoDbReader.GetCollection <TDocument, TKey>(partitionKey)); }
/// <summary> /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. /// </summary> /// <typeparam name="TDocument">The document type.</typeparam> /// <typeparam name="TKey">The type of the primary key.</typeparam> /// <typeparam name="TValue">The type of the value used to order the query.</typeparam> /// <param name="filter">A LINQ expression filter.</param> /// <param name="maxValueSelector">A property selector to select the max value.</param> /// <param name="partitionKey">An optional partitionKey.</param> public async virtual Task <TValue> GetMaxValueAsync <TDocument, TKey, TValue>(Expression <Func <TDocument, bool> > filter, Expression <Func <TDocument, TValue> > maxValueSelector, string partitionKey = null) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> { return(await MongoDbReader.GetMaxValueAsync <TDocument, TKey, TValue>(filter, maxValueSelector, partitionKey)); }
/// <summary> /// Returns one document given an expression filter. /// </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="filter">A LINQ expression filter.</param> /// <param name="partitionKey">An optional partition key.</param> public virtual TDocument GetOne <TDocument, TKey>(Expression <Func <TDocument, bool> > filter, string partitionKey = null) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> { return(MongoDbReader.GetOne <TDocument, TKey>(filter, partitionKey)); }
/// <summary> /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. /// </summary> /// <typeparam name="TDocument">The document type.</typeparam> /// <typeparam name="TKey">The type of the primary key.</typeparam> /// <typeparam name="TValue">The type of the value used to order the query.</typeparam> /// <param name="filter">A LINQ expression filter.</param> /// <param name="minValueSelector">A property selector to order by ascending.</param> /// <param name="partitionKey">An optional partition key.</param> public virtual TValue GetMinValue <TDocument, TKey, TValue>(Expression <Func <TDocument, bool> > filter, Expression <Func <TDocument, TValue> > minValueSelector, string partitionKey = null) where TDocument : IDocument <TKey> where TKey : IEquatable <TKey> { return(MongoDbReader.GetMinValue <TDocument, TKey, TValue>(filter, minValueSelector, partitionKey)); }
public BaseMongoRepositoryRead(MongoDbReader mongoDbReader) { _mongoDbReader = mongoDbReader; }
/// <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 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(MongoDbReader.CountAsync <TDocument, TKey>(condition, countOption, partitionKey, cancellationToken)); }