Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2710

Provide a way to refer to a $lookup let variable in lookup pipeline expression

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Builders

    Description

      There appears to be no way to refer to a let variable defined in a lookup, using a lambda expression.  I wind up having to create a string based pipeline for the lookup.

              // There is no way to refer to a let variable ($$products) from a lambda function.
              // We have to use a BsonDocument (strings unfortunately) to define our lookup pipeline.
              private const string DeliveriesLookupPipelineString = @"
      {$match:{
        $expr:{
          $and:[
            {$in:[""$productId"",""$$products.productId""]},
            {$eq:[""$deliveryType"",""Sample""]},
            {$eq:[""$availability"",""Released""]}
           ]
        }
       }
      }
      ";
       
              private static readonly PipelineDefinition<Delivery, Delivery> DeliveriesLookupPipeline = new[]
              {
                  BsonDocument.Parse(DeliveriesLookupPipelineString)
              };
      ...
                      .Lookup<SearchAugmentedProductType, Delivery, Delivery, IEnumerable<Delivery>,
                          SearchAugmentedProductType>(
                          _deliveries,
                          new BsonDocument { { "products", "$products" } },
                          DeliveriesLookupPipeline,
                          searchAugmentedProductType => searchAugmentedProductType.Deliveries)
      ...
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            rcollette@yahoo.com Richard Collette
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: