// private methods private IAggregateFluent<C> CreateSubject() { var settings = new MongoCollectionSettings(); _collection = Substitute.For<IMongoCollection<C>>(); _collection.DocumentSerializer.Returns(BsonSerializer.SerializerRegistry.GetSerializer<C>()); _collection.Settings.Returns(settings); var options = new AggregateOptions(); var subject = new AggregateFluent<C, C>(_collection, Enumerable.Empty<IPipelineStageDefinition>(), options); return subject; }
public virtual Task <IAsyncCursor <TResult> > AggregateAsync <TResult>(IClientSessionHandle session, PipelineDefinition <TVal, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = new CancellationToken()) => throw new NotImplementedException();
public Task AggregateToCollectionAsync <TResult>(IClientSessionHandle session, PipelineDefinition <TVal, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) => throw new NotImplementedException();
/// <summary> /// 查询返回单条 /// </summary> /// <typeparam name="T">集合类型</typeparam> /// <param name="collection">集合</param> /// <param name="session">会话句柄(作用于事务)</param> /// <param name="id">文档默认ID</param> /// <param name="options">聚合操作设置</param> /// <returns></returns> public static T MatchOne <T>(this IMongoCollection <T> collection, IClientSessionHandle session, string id, AggregateOptions options = null) where T : BaseMongoEntity { return(collection.AsQueryable(session, options).FirstOrDefault(f => f.Id == id)); }
/// <summary> /// 查询返回单条 /// </summary> /// <typeparam name="T">集合类型</typeparam> /// <param name="collection">集合</param> /// <param name="session">会话句柄(作用于事务)</param> /// <param name="filter">Lmabda过滤器</param> /// <param name="options">聚合操作设置</param> /// <returns></returns> public static T MatchOne <T>(this IMongoCollection <T> collection, IClientSessionHandle session, Expression <Func <T, bool> > filter, AggregateOptions options = null) where T : BaseMongoEntity { return(collection.AsQueryable(session, options).FirstOrDefault(filter)); }
/// <summary> /// Start a fluent aggregation pipeline with a $text stage with the supplied parameters. /// <para>TIP: Make sure to define a text index with DB.Index<T>() before searching</para> /// </summary> /// <param name="searchType">The type of text matching to do</param> /// <param name="searchTerm">The search term</param> /// <param name="caseSensitive">Case sensitivity of the search (optional)</param> /// <param name="diacriticSensitive">Diacritic sensitivity of the search (optional)</param> /// <param name="language">The language for the search (optional)</param> /// <param name="options">Options for finding documents (not required)</param> /// <param name="session">An optional session if using within a transaction</param> public IAggregateFluent <T> FluentTextSearch <T>(Search searchType, string searchTerm, bool caseSensitive = false, bool diacriticSensitive = false, string language = null, AggregateOptions options = null, IClientSessionHandle session = null, bool _ = false) where T : IEntity { return(FluentTextSearch <T>(searchType, searchTerm, caseSensitive, diacriticSensitive, language, options, session)); }
/// <summary> /// Exposes the MongoDB collection for the given IEntity as an IAggregateFluent in order to facilitate Fluent queries. /// </summary> /// <typeparam name="T">Any class that implements IEntity</typeparam> /// <param name="options">The options for the aggregation. This is not required.</param> /// <param name="session">An optional session if using within a transaction</param> public IAggregateFluent <T> Fluent <T>(AggregateOptions options = null, IClientSessionHandle session = null, bool _ = false) where T : IEntity { return(Fluent <T>(options, session)); }
/// <inheritdoc/> public Task <IAsyncCursor <TResult> > AggregateAsync <TResult>(IClientSessionHandle session, PipelineDefinition <T, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { throw new System.NotImplementedException(); }
/// <inheritdoc/> public async Task <List <T> > AggregateAsync(PipelineDefinition <T, T> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { var database = client.GetDatabase(databaseName); var myCollection = database.GetCollection <T>(collectionName); var result = (await myCollection.AggregateAsync(pipeline, options, cancellationToken).ConfigureAwait(false)).ToList(cancellationToken); return(result); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public IQueryable <T> GetQuery <T>(AggregateOptions options = null) { return(_mongoDatabase.GetCollection <T>(typeof(T).Name).AsQueryable(options)); }
/// <summary> /// Start a fluent aggregation pipeline with a $GeoNear stage with the supplied parameters. /// </summary> /// <param name="NearCoordinates">The coordinates from which to find documents from</param> /// <param name="DistanceField">x => x.Distance</param> /// <param name="Spherical">Calculate distances using spherical geometry or not</param> /// <param name="MaxDistance">The maximum distance from the center point that the documents can be</param> /// <param name="MinDistance">The minimum distance from the center point that the documents can be</param> /// <param name="Limit">The maximum number of documents to return</param> /// <param name="Query">Limits the results to the documents that match the query</param> /// <param name="DistanceMultiplier">The factor to multiply all distances returned by the query</param> /// <param name="IncludeLocations">Specify the output field to store the point used to calculate the distance</param> /// <param name="IndexKey"></param> /// <param name="options">The options for the aggregation. This is not required.</param> /// <param name="session">An optional session if using within a transaction</param> public IAggregateFluent <T> FluentGeoNear <T>(Coordinates2D NearCoordinates, Expression <Func <T, object> > DistanceField, bool Spherical = true, double?MaxDistance = null, double?MinDistance = null, int?Limit = null, BsonDocument Query = null, double?DistanceMultiplier = null, Expression <Func <T, object> > IncludeLocations = null, string IndexKey = null, AggregateOptions options = null, IClientSessionHandle session = null) where T : IEntity { return(FluentGeoNear(NearCoordinates, DistanceField, Spherical, MaxDistance, MinDistance, Limit, Query, DistanceMultiplier, IncludeLocations, IndexKey, options, session, DbName)); }
public Task <IAsyncCursor <TResult> > AggregateAsync <TResult>(IClientSessionHandle session, PipelineDefinition <TModel, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(_collection.AggregateAsync(session, pipeline, options, cancellationToken)); }
public IAsyncCursor <TResult> Aggregate <TResult>(PipelineDefinition <TModel, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(_collection.Aggregate(pipeline, options, cancellationToken)); }
/// <summary> /// 查询返回单条 /// </summary> /// <typeparam name="T">集合类型</typeparam> /// <param name="collection">集合</param> /// <param name="session">会话句柄(作用于事务)</param> /// <param name="id">文档默认ID</param> /// <param name="options">聚合操作设置</param> /// <returns></returns> public static Task <T> MatchOneAsync <T>(this IMongoCollection <T> collection, IClientSessionHandle session, string id, AggregateOptions options = null) where T : BaseMongoEntity { return(Task.Run(() => MatchOne(collection, session, id, options))); }
/// <summary> /// 查询返回集合 /// </summary> /// <typeparam name="T">文档类型</typeparam> /// <param name="collection">集合</param> /// <param name="session">会话句柄(作用于事务)</param> /// <param name="filte">Lambda过滤器</param> /// <param name="options">聚合操作设置</param> /// <returns></returns> public static Task <IEnumerable <T> > MatchAsync <T>(this IMongoCollection <T> collection, IClientSessionHandle session, Expression <Func <T, bool> > filter, AggregateOptions options = null) where T : BaseMongoEntity { return(Task.Run(() => Match(collection, session, filter, options))); }
/// <summary> /// 查询返回单条 /// </summary> /// <typeparam name="T">集合类型</typeparam> /// <param name="collection">集合</param> /// <param name="filter">Lmabda过滤器</param> /// <param name="options">聚合操作设置</param> /// <returns></returns> public static Task <T> MatchOneAsync <T>(this IMongoCollection <T> collection, Expression <Func <T, bool> > filter, AggregateOptions options = null) where T : BaseMongoEntity { return(Task.Run(() => MatchOne(collection, filter, options))); }
/// <inheritdoc/> public IAsyncCursor <TResult> Aggregate <TResult>(PipelineDefinition <T, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { throw new System.NotImplementedException(); }
internal override object Execute <TInput>(IMongoCollection <TInput> collection, AggregateOptions options) { var pipeline = CreatePipeline <TInput>(); return(collection.Aggregate(pipeline, options, CancellationToken.None)); }
/// <summary> /// Exposes the MongoDB collection for the given IEntity as an IAggregateFluent in order to facilitate Fluent queries. /// </summary> /// <typeparam name="T">Any class that implements IEntity</typeparam> /// <param name="options">The options for the aggregation. This is not required.</param> /// <param name="session">An optional session if using within a transaction</param> public static IAggregateFluent <T> Fluent <T>(AggregateOptions options = null, IClientSessionHandle session = null) where T : IEntity { return(session == null ? Collection <T>().Aggregate(options) : Collection <T>().Aggregate(session, options)); }
internal override Task ExecuteAsync <TInput>(IMongoCollection <TInput> collection, AggregateOptions options, CancellationToken cancellationToken) { var pipeline = CreatePipeline <TInput>(); return(collection.AggregateAsync(pipeline, options, cancellationToken)); }
/// <summary> /// Start a fluent aggregation pipeline with a $text stage with the supplied parameters. /// <para>TIP: Make sure to define a text index with DB.Index<T>() before searching</para> /// </summary> /// <param name="searchType">The type of text matching to do</param> /// <param name="searchTerm">The search term</param> /// <param name="caseSensitive">Case sensitivity of the search (optional)</param> /// <param name="diacriticSensitive">Diacritic sensitivity of the search (optional)</param> /// <param name="language">The language for the search (optional)</param> /// <param name="options">Options for finding documents (not required)</param> /// <param name="session">An optional session if using within a transaction</param> public static IAggregateFluent <T> FluentTextSearch <T>(Search searchType, string searchTerm, bool caseSensitive = false, bool diacriticSensitive = false, string language = null, AggregateOptions options = null, IClientSessionHandle session = null) where T : IEntity { if (searchType == Search.Fuzzy) { searchTerm = searchTerm.ToDoubleMetaphoneHash(); caseSensitive = false; diacriticSensitive = false; language = null; } var filter = Builders <T> .Filter.Text( searchTerm, new TextSearchOptions { CaseSensitive = caseSensitive, DiacriticSensitive = diacriticSensitive, Language = language }); return(session == null ? Collection <T>().Aggregate(options).Match(filter) : Collection <T>().Aggregate(session, options).Match(filter)); }
public override IAsyncCursor <TResult> Aggregate <TResult>(PipelineDefinition <TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { var operation = new AggregateOperation <TDocument, TResult>(_documents, pipeline, options); var result = operation.Execute(); var desirializedDocuments = DeserializeDocuments(result, BsonSerializer.LookupSerializer <TResult>()); return(new AsyncCursor <TResult>(desirializedDocuments)); }
/// <summary> /// Gets the underlying mongo collection for the provided information in Queryable mode. /// </summary> /// <param name="collectionName">The collection in the corresponding mongo database.</param> /// <param name="databaseName">An optional mongo database to connect to.</param> /// <param name="client">An optional client with which to connect.</param> /// <param name="aggregateOptions">An optional set of aggregation options for the queryable call.</param> /// <typeparam name="T">The type of data that this collection houses.</typeparam> /// <remarks> /// Use the optional "databaseName" if the intent is to connect to a database other that what was provided during application startup. /// </remarks> /// <returns>A <see cref="IMongoQueryable{T}"/>.</returns> public IQueryable <T> GetCollectionAsQueryable <T>(string collectionName, string databaseName = null, IMongoClient client = null, AggregateOptions aggregateOptions = null) { var col = this.GetCollection <T>(collectionName, databaseName, client); return(col.AsQueryable(aggregateOptions)); }
public IMongoQueryable <TDocument> AsQueryable(AggregateOptions aggregateOptions = default) { return(Collection.AsQueryable(aggregateOptions)); }
/// <summary> /// 查询返回集合 /// </summary> /// <typeparam name="T">文档类型</typeparam> /// <param name="collection">集合</param> /// <param name="session">会话句柄(作用于事务)</param> /// <param name="filte">Lambda过滤器</param> /// <param name="options">聚合操作设置</param> /// <returns></returns> public static IEnumerable <T> Match <T>(this IMongoCollection <T> collection, IClientSessionHandle session, Expression <Func <T, bool> > filte, AggregateOptions options = null) where T : BaseMongoEntity { return(collection.AsQueryable(session, options).Where(filte)); }
/// <summary> /// Start a fluent aggregation pipeline with a $GeoNear stage with the supplied parameters. /// </summary> /// <param name="NearCoordinates">The coordinates from which to find documents from</param> /// <param name="DistanceField">x => x.Distance</param> /// <param name="Spherical">Calculate distances using spherical geometry or not</param> /// <param name="MaxDistance">The maximum distance in meters from the center point that the documents can be</param> /// <param name="MinDistance">The minimum distance in meters from the center point that the documents can be</param> /// <param name="Limit">The maximum number of documents to return</param> /// <param name="Query">Limits the results to the documents that match the query</param> /// <param name="DistanceMultiplier">The factor to multiply all distances returned by the query</param> /// <param name="IncludeLocations">Specify the output field to store the point used to calculate the distance</param> /// <param name="IndexKey"></param> /// <param name="options">The options for the aggregation. This is not required.</param> /// <param name="session">An optional session if using within a transaction</param> public static IAggregateFluent <T> FluentGeoNear <T>(Coordinates2D NearCoordinates, Expression <Func <T, object> > DistanceField, bool Spherical = true, double?MaxDistance = null, double?MinDistance = null, int?Limit = null, BsonDocument Query = null, double?DistanceMultiplier = null, Expression <Func <T, object> > IncludeLocations = null, string IndexKey = null, AggregateOptions options = null, IClientSessionHandle session = null) where T : IEntity { return(new GeoNear <T> { near = NearCoordinates, distanceField = DistanceField?.FullPath(), spherical = Spherical, maxDistance = MaxDistance, minDistance = MinDistance, query = Query, distanceMultiplier = DistanceMultiplier, limit = Limit, includeLocs = IncludeLocations?.FullPath(), key = IndexKey, } .ToFluent(options, session)); }
public void AggregateToCollection <TResult>(PipelineDefinition <TVal, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) => throw new NotImplementedException();
public void AggregateToCollection_should_add_match_to_beginning_of_pipeline( [Values(false, true)] bool usingSession, [Values(false, true)] bool async) { var subject = CreateSubject(); var session = CreateSession(usingSession); var options = new AggregateOptions(); if (async) { if (usingSession) { subject.AggregateToCollectionAsync <B>(session, new[] { new BsonDocument("$skip", 10) }, options, CancellationToken.None); _mockDerivedCollection.Verify( c => c.AggregateToCollectionAsync( session, It.Is <PipelineDefinition <B, B> >(p => RenderPipeline(p)[0].Equals(new BsonDocument("$match", _ofTypeFilter))), options, CancellationToken.None), Times.Once); } else { subject.AggregateToCollectionAsync <B>(new[] { new BsonDocument("$skip", 10) }, options, CancellationToken.None); _mockDerivedCollection.Verify( c => c.AggregateToCollectionAsync( It.Is <PipelineDefinition <B, B> >(p => RenderPipeline(p)[0].Equals(new BsonDocument("$match", _ofTypeFilter))), options, CancellationToken.None), Times.Once); } } else { if (usingSession) { subject.AggregateToCollection <B>(session, new[] { new BsonDocument("$skip", 10) }, options, CancellationToken.None); _mockDerivedCollection.Verify( c => c.AggregateToCollection( session, It.Is <PipelineDefinition <B, B> >(p => RenderPipeline(p)[0].Equals(new BsonDocument("$match", _ofTypeFilter))), options, CancellationToken.None), Times.Once); } else { subject.AggregateToCollection <B>(new[] { new BsonDocument("$skip", 10) }, options, CancellationToken.None); _mockDerivedCollection.Verify( c => c.AggregateToCollection( It.Is <PipelineDefinition <B, B> >(p => RenderPipeline(p)[0].Equals(new BsonDocument("$match", _ofTypeFilter))), options, CancellationToken.None), Times.Once); } } }
public virtual IAsyncCursor <TResult> Aggregate <TResult>(PipelineDefinition <TVal, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = new CancellationToken()) => throw new NotImplementedException();
public static Task <IAggregateFluent <TEntity> > GetAggregateAsync <TEntity>(this IReadOnlyBasicRepository <TEntity> repository, CancellationToken cancellationToken = default, AggregateOptions aggregateOptions = null) where TEntity : class, IEntity { return(repository.ToMongoDbRepository().GetAggregateAsync(cancellationToken, aggregateOptions)); }
/// <summary> /// Returns an aggregate in a list or database /// </summary> /// <param name="function_num">Which function to use.</param> /// <param name="options">Which values to ignore in the evaluation range for the function.</param> /// <param name="refs">The numeric arguments for which you want the aggregate value.</param> /// <returns>An aggregate in a list or database. The AGGREGATE function can apply different aggregate functions to a list or database with the option to ignore hidden rows and error values.</returns> public static double AGGREGATE(AggregateFunction function_num, AggregateOptions options, params double[] refs) { throw new NotImplementedException(); }
/// <summary> /// An IAggregateFluent collection of sibling Entities. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="session">An optional session if using within a transaction</param> /// <param name="options">The options for the aggregation. This is not required.</param> public static IAggregateFluent <T> Fluent <T>(this T _, IClientSessionHandle session = null, AggregateOptions options = null) where T : IEntity { return(DB.Fluent <T>(options, session)); }