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

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Builders
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      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)
      ...
      

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

              Created:
              Updated: