Пример #1
0
 /// <summary>
 /// Appends a $graphLookup stage to the pipeline.
 /// </summary>
 /// <typeparam name="TResult">The type of the result.</typeparam>
 /// <typeparam name="TFrom">The type of the from documents.</typeparam>
 /// <param name="aggregate">The aggregate.</param>
 /// <param name="from">The from collection.</param>
 /// <param name="connectFromField">The connect from field.</param>
 /// <param name="connectToField">The connect to field.</param>
 /// <param name="startWith">The start with value.</param>
 /// <param name="as">The as field.</param>
 /// <param name="depthField">The depth field.</param>
 /// <returns>The fluent aggregate interface.</returns>
 public static IAggregateFluent <BsonDocument> GraphLookup <TResult, TFrom>(
     this IAggregateFluent <TResult> aggregate,
     IMongoCollection <TFrom> from,
     FieldDefinition <TFrom, BsonValue> connectFromField,
     FieldDefinition <TFrom, BsonValue> connectToField,
     AggregateExpressionDefinition <TResult, BsonValue> startWith,
     FieldDefinition <BsonDocument, IEnumerable <BsonDocument> > @as,
     FieldDefinition <BsonDocument, int> depthField = null)
 {
     Ensure.IsNotNull(aggregate, nameof(aggregate));
     return(aggregate.AppendStage(PipelineStageDefinitionBuilder.GraphLookup(from, connectFromField, connectToField, startWith, @as, depthField)));
 }
Пример #2
0
 /// <summary>
 /// Appends a $graphLookup stage to the pipeline.
 /// </summary>
 /// <typeparam name="TResult">The type of the result.</typeparam>
 /// <typeparam name="TNewResult">The type of the new result (must be same as TResult with an additional as field).</typeparam>
 /// <typeparam name="TFrom">The type of the from documents.</typeparam>
 /// <typeparam name="TConnectFrom">The type of the connect from field (must be either TConnectTo or a type that implements IEnumerable{TConnectTo}).</typeparam>
 /// <typeparam name="TConnectTo">The type of the connect to field.</typeparam>
 /// <typeparam name="TStartWith">The type of the start with expression (must be either TConnectTo or a type that implements IEnumerable{TConnectTo}).</typeparam>
 /// <typeparam name="TAs">The type of the as field.</typeparam>
 /// <param name="aggregate">The aggregate.</param>
 /// <param name="from">The from collection.</param>
 /// <param name="connectFromField">The connect from field.</param>
 /// <param name="connectToField">The connect to field.</param>
 /// <param name="startWith">The start with value.</param>
 /// <param name="as">The as field.</param>
 /// <param name="options">The options.</param>
 /// <returns>The fluent aggregate interface.</returns>
 public static IAggregateFluent <TNewResult> GraphLookup <TResult, TFrom, TConnectFrom, TConnectTo, TStartWith, TAs, TNewResult>(
     this IAggregateFluent <TResult> aggregate,
     IMongoCollection <TFrom> from,
     Expression <Func <TFrom, TConnectFrom> > connectFromField,
     Expression <Func <TFrom, TConnectTo> > connectToField,
     Expression <Func <TResult, TStartWith> > startWith,
     Expression <Func <TNewResult, TAs> > @as,
     AggregateGraphLookupOptions <TFrom, TFrom, TNewResult> options = null)
     where TAs : IEnumerable <TFrom>
 {
     Ensure.IsNotNull(aggregate, nameof(aggregate));
     return(aggregate.AppendStage(PipelineStageDefinitionBuilder.GraphLookup(from, connectFromField, connectToField, startWith, @as, options, aggregate.Options?.TranslationOptions)));
 }
Пример #3
0
        public void GraphLookup_with_one_to_one_parameters_should_return_expected_result()
        {
            RequireServer.Check().Supports(Feature.AggregateGraphLookupStage);
            var database   = GetDatabase();
            var collection = database.GetCollection <OneToOne>("collectionOneToOne");

            var result = PipelineStageDefinitionBuilder.GraphLookup(
                from: collection,
                connectFromField: x => x.From,
                connectToField: x => x.To,
                startWith: (OneToOne x) => x.From,
                @as: (OneToOneResult x) => x.Matches);

            RenderStage(result).Document.Should().Be(
                @"{
                    $graphLookup : {
                        from : 'collectionOneToOne',
                        connectFromField : 'From',
                        connectToField : 'To',
                        startWith : '$From',
                        as : 'Matches'
                    }
                }");
        }