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