[CSHARP-2710] Provide a way to refer to a $lookup let variable in lookup pipeline expression Created: 23/Aug/19  Updated: 31/Mar/22

Status: Backlog
Project: C# Driver
Component/s: Builders
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Richard Collette Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: rp-track
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


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



 Comments   
Comment by Richard Collette [ 23/Aug/19 ]

As a side comment, it seems that I am always having to specify a fairly long list of generic type parameters rather than having them get inferred.

Generated at Wed Feb 07 21:43:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.