public ETTask <List <ComponentWithId> > GetJson(string collectionName, string json, long skip, long limit) { ETTaskCompletionSource <List <ComponentWithId> > tcs = new ETTaskCompletionSource <List <ComponentWithId> >(); PipelineStageDefinition <ComponentWithId, ComponentWithId> _match = PipelineStageDefinitionBuilder.Match <ComponentWithId>(json); PipelineStageDefinition <ComponentWithId, ComponentWithId> _skip = PipelineStageDefinitionBuilder.Skip <ComponentWithId>((int)skip); PipelineStageDefinition <ComponentWithId, ComponentWithId> _limit = PipelineStageDefinitionBuilder.Limit <ComponentWithId>((int)limit); PipelineDefinition <ComponentWithId, ComponentWithId> pipeline = new PipelineStagePipelineDefinition <ComponentWithId, ComponentWithId>( new PipelineStageDefinition <ComponentWithId, ComponentWithId>[] { _match, _skip, _limit }); DBQueryPipelineTask dbQueryPipelineTask = ComponentFactory.Create <DBQueryPipelineTask, string, PipelineDefinition <ComponentWithId, ComponentWithId>, ETTaskCompletionSource <List <ComponentWithId> > > (collectionName, pipeline, tcs); this.tasks[(int)((ulong)dbQueryPipelineTask.Id % taskCount)].Add(dbQueryPipelineTask); return(tcs.Task); }
private static void ApplyProjection <TEntity, TProperty>(AggregateQueryable <TEntity> aggregateQueryable, string asFieldName, string navigationElementName) { var isEnumerable = typeof(TProperty).IsEnumerable(); if (!isEnumerable) { //Set first element as navigation field PipelineStageDefinition <TEntity, TEntity> addFields = "{ \"$addFields\": { \"" + navigationElementName + "\": { \"$arrayElemAt\": [\"$" + asFieldName + "\", 0] } } }"; //Exclude temp @as field PipelineStageDefinition <TEntity, TEntity> project = "{ \"$project\" : { \"" + asFieldName + "\" : 0 } }"; aggregateQueryable.AggregateFluent = aggregateQueryable.AggregateFluent .AppendStage(addFields) .AppendStage(project); } }
/// <summary> /// Adds a distinct aggregation stage to a fluent pipeline. /// </summary> /// <typeparam name="T">Any class that implements IEntity</typeparam> public static IAggregateFluent <T> Distinct <T>(this IAggregateFluent <T> aggregate) where T : IEntity { PipelineStageDefinition <T, T> groupStage = @" { $group: { _id: '$_id', doc: { $first: '$$ROOT' } } }"; PipelineStageDefinition <T, T> rootStage = @" { $replaceRoot: { newRoot: '$doc' } }"; return(aggregate.AppendStage(groupStage).AppendStage(rootStage)); }
/// <summary> /// Appends a match stage to the pipeline with an aggregation expression (i.e. $expr) /// </summary> /// <typeparam name="T">Any class that implements IEntity</typeparam> /// <param name="aggregate"></param> /// <param name="expression">{ $gt: ['$Property1', '$Property2'] }</param> public static IAggregateFluent <T> MatchExpression <T>(this IAggregateFluent <T> aggregate, string expression) where T : IEntity { PipelineStageDefinition <T, T> stage = "{$match:{$expr:" + expression + "}}"; return(aggregate.AppendStage(stage)); }
private RenderedPipelineStageDefinition <TOutput> RenderStage <TInput, TOutput>(PipelineStageDefinition <TInput, TOutput> stage) { var registry = BsonSerializer.SerializerRegistry; var serializer = registry.GetSerializer <TInput>(); return(stage.Render(serializer, registry)); }
// private methods private RenderedPipelineStageDefinition <ChangeStreamDocument <BsonDocument> > RenderStage(PipelineStageDefinition <BsonDocument, ChangeStreamDocument <BsonDocument> > stage) { return(stage.Render(BsonDocumentSerializer.Instance, BsonSerializer.SerializerRegistry)); }
public static BsonDocument Render <TInput, TOutput>(PipelineStageDefinition <TInput, TOutput> stage, IBsonSerializer <TInput> inputSerializer, LinqProvider linqProvider) { var rendered = stage.Render(inputSerializer, BsonSerializer.SerializerRegistry, linqProvider); return(rendered.Document); }
public IAggregateFluent <TNewResult> AppendStage <TNewResult>(PipelineStageDefinition <BsonDocument, TNewResult> stage) { return(BlockProvider.AppendStage <TNewResult>(stage)); }