/// <inheritdoc />
 public virtual IAggregateFluent <TNewResult> Lookup <TForeignDocument, TAsElement, TAs, TNewResult>(
     IMongoCollection <TForeignDocument> foreignCollection,
     BsonDocument let,
     PipelineDefinition <TForeignDocument, TAsElement> lookupPipeline,
     FieldDefinition <TNewResult, TAs> @as,
     AggregateLookupOptions <TForeignDocument, TNewResult> options = null)
     where TAs : IEnumerable <TAsElement>
 {
     throw new NotImplementedException();
 }
예제 #2
0
 public override IAggregateFluent <TNewResult> Lookup <TForeignDocument, TAsElement, TAs, TNewResult>(
     IMongoCollection <TForeignDocument> foreignCollection,
     BsonDocument let,
     PipelineDefinition <TForeignDocument, TAsElement> lookupPipeline,
     FieldDefinition <TNewResult, TAs> @as,
     AggregateLookupOptions <TForeignDocument, TNewResult> options = null)
 {
     Ensure.IsNotNull(foreignCollection, nameof(foreignCollection));
     return(WithPipeline(_pipeline.Lookup(foreignCollection, let, lookupPipeline, @as)));
 }
예제 #3
0
 /// <summary>
 /// Appends a lookup stage to the pipeline.
 /// </summary>
 /// <typeparam name="TResult">The type of the result.</typeparam>
 /// <typeparam name="TForeignDocument">The type of the foreign collection.</typeparam>
 /// <typeparam name="TNewResult">The type of the new result.</typeparam>
 /// <param name="aggregate">The aggregate.</param>
 /// <param name="foreignCollection">The foreign collection.</param>
 /// <param name="localField">The local field.</param>
 /// <param name="foreignField">The foreign field.</param>
 /// <param name="as">The field in the result to place the foreign matches.</param>
 /// <param name="options">The options.</param>
 /// <returns>The fluent aggregate interface.</returns>
 public static IAggregateFluent <TNewResult> Lookup <TResult, TForeignDocument, TNewResult>(
     this IAggregateFluent <TResult> aggregate,
     IMongoCollection <TForeignDocument> foreignCollection,
     Expression <Func <TResult, object> > localField,
     Expression <Func <TForeignDocument, object> > foreignField,
     Expression <Func <TNewResult, object> > @as,
     AggregateLookupOptions <TForeignDocument, TNewResult> options = null)
 {
     Ensure.IsNotNull(aggregate, nameof(aggregate));
     return(aggregate.AppendStage(PipelineStageDefinitionBuilder.Lookup(foreignCollection, localField, foreignField, @as, options)));
 }
예제 #4
0
 /// <summary>
 /// Appends a lookup stage to the pipeline.
 /// </summary>
 /// <typeparam name="TResult">The type of the result.</typeparam>
 /// <typeparam name="TForeignDocument">The type of the foreign collection documents.</typeparam>
 /// <typeparam name="TAsElement">The type of the as field elements.</typeparam>
 /// <typeparam name="TAs">The type of the as field.</typeparam>
 /// <typeparam name="TNewResult">The type of the new result.</typeparam>
 /// <param name="aggregate">The aggregate.</param>
 /// <param name="foreignCollection">The foreign collection.</param>
 /// <param name="let">The "let" definition.</param>
 /// <param name="lookupPipeline">The lookup pipeline.</param>
 /// <param name="as">The as field in <typeparamref name="TNewResult" /> in which to place the results of the lookup pipeline.</param>
 /// <param name="options">The options.</param>
 /// <returns>The fluent aggregate interface.</returns>
 public static IAggregateFluent <TNewResult> Lookup <TResult, TForeignDocument, TAsElement, TAs, TNewResult>(
     this IAggregateFluent <TResult> aggregate,
     IMongoCollection <TForeignDocument> foreignCollection,
     BsonDocument let,
     PipelineDefinition <TForeignDocument, TAsElement> lookupPipeline,
     Expression <Func <TNewResult, TAs> > @as,
     AggregateLookupOptions <TForeignDocument, TNewResult> options = null)
     where TAs : IEnumerable <TAsElement>
 {
     Ensure.IsNotNull(aggregate, nameof(aggregate));
     return(aggregate.AppendStage(PipelineStageDefinitionBuilder.Lookup <TResult, TForeignDocument, TAsElement, TAs, TNewResult>(
                                      foreignCollection,
                                      let,
                                      lookupPipeline,
                                      @as,
                                      options)));
 }
        public override IAggregateFluent <TNewResult> Lookup <TForeignDocument, TNewResult>(string foreignCollectionName, FieldDefinition <TResult> localField, FieldDefinition <TForeignDocument> foreignField, FieldDefinition <TNewResult> @as, AggregateLookupOptions <TForeignDocument, TNewResult> options)
        {
            Ensure.IsNotNull(foreignCollectionName, nameof(foreignCollectionName));
            var foreignCollection = _collection.Database.GetCollection <TForeignDocument>(foreignCollectionName);

            return(WithPipeline(_pipeline.Lookup(foreignCollection, localField, foreignField, @as, options)));
        }
        public override IAggregateFluent <TNewResult> Lookup <TForeignDocument, TNewResult>(string foreignCollectionName, FieldDefinition <TResult> localField, FieldDefinition <TForeignDocument> foreignField, FieldDefinition <TNewResult> @as, AggregateLookupOptions <TForeignDocument, TNewResult> options)
        {
            options = options ?? new AggregateLookupOptions <TForeignDocument, TNewResult>();
            const string operatorName = "$lookup";
            var          stage        = new DelegatedPipelineStageDefinition <TResult, TNewResult>(
                operatorName,
                (localSerializer, sr) =>
            {
                var foreignSerializer   = options.ForeignSerializer ?? (localSerializer as IBsonSerializer <TForeignDocument>) ?? sr.GetSerializer <TForeignDocument>();
                var newResultSerializer = options.ResultSerializer ?? (localSerializer as IBsonSerializer <TNewResult>) ?? sr.GetSerializer <TNewResult>();
                return(new RenderedPipelineStageDefinition <TNewResult>(
                           operatorName, new BsonDocument(operatorName, new BsonDocument
                {
                    { "from", foreignCollectionName },
                    { "localField", localField.Render(localSerializer, sr).FieldName },
                    { "foreignField", foreignField.Render(foreignSerializer, sr).FieldName },
                    { "as", @as.Render(newResultSerializer, sr).FieldName }
                }),
                           newResultSerializer));
            });

            return(AppendStage <TNewResult>(stage));
        }
예제 #7
0
 /// <inheritdoc />
 public virtual IAggregateFluent <TNewResult> Lookup <TForeignDocument, TNewResult>(string foreignCollectionName, FieldDefinition <TResult> localField, FieldDefinition <TForeignDocument> foreignField, FieldDefinition <TNewResult> @as, AggregateLookupOptions <TForeignDocument, TNewResult> options)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Appends a lookup stage to the pipeline.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <typeparam name="TForeignDocument">The type of the foreign collection.</typeparam>
        /// <typeparam name="TNewResult">The type of the new result.</typeparam>
        /// <param name="aggregate">The aggregate.</param>
        /// <param name="foreignCollection">The foreign collection.</param>
        /// <param name="localField">The local field.</param>
        /// <param name="foreignField">The foreign field.</param>
        /// <param name="as">The field in the result to place the foreign matches.</param>
        /// <param name="options">The options.</param>
        /// <returns>The fluent aggregate interface.</returns>
        public static IAggregateFluent <TNewResult> Lookup <TResult, TForeignDocument, TNewResult>(this IAggregateFluent <TResult> aggregate,
                                                                                                   IMongoCollection <TForeignDocument> foreignCollection,
                                                                                                   Expression <Func <TResult, object> > localField,
                                                                                                   Expression <Func <TForeignDocument, object> > foreignField,
                                                                                                   Expression <Func <TNewResult, object> > @as,
                                                                                                   AggregateLookupOptions <TForeignDocument, TNewResult> options = null)
        {
            Ensure.IsNotNull(aggregate, nameof(aggregate));
            Ensure.IsNotNull(foreignCollection, nameof(foreignCollection));
            Ensure.IsNotNull(localField, nameof(localField));
            Ensure.IsNotNull(foreignField, nameof(foreignField));
            Ensure.IsNotNull(@as, nameof(@as));

            options = options ?? new AggregateLookupOptions <TForeignDocument, TNewResult>();
            if (options.ForeignSerializer == null)
            {
                options.ForeignSerializer = foreignCollection.DocumentSerializer;
            }

            return(aggregate.Lookup(
                       foreignCollection.CollectionNamespace.CollectionName,
                       new ExpressionFieldDefinition <TResult>(localField),
                       new ExpressionFieldDefinition <TForeignDocument>(foreignField),
                       new ExpressionFieldDefinition <TNewResult>(@as),
                       options));
        }