Hey, i want to use the IAggregateFluent.Lookup<TForeignDocument, TAsElement, TAs, TNewResult> Method. (The Lookup Method)
This is my MQL Pipeline:
[{
$lookup: {
from: 'images',
'let': {
id: '$productId',
bool: true
},
pipeline: [
{
$match: {
$expr: {
$and: [
{
$eq: [
'$product',
'$$id'
]
},
{
$eq: [
'$overviewimage',
'$$bool'
]
}
]
}
}
},
{
$project: {
_id: 0,
url: 1,
description: 1,
product: 1
}
}
],
as: 'image'
}
}]
This is my Code:
var let = new BsonDocument
{
{ "id", "$productId" },
{ "bool", true }
} ;
var matchStage = new BsonDocument("$match",
new BsonDocument("$expr",
new BsonDocument("$and",
new BsonArray
{
new BsonDocument("$eq",
new BsonArray
{
"$product",
"$$id"
}),
new BsonDocument("$eq",
new BsonArray
{
"$overviewimage",
"$$bool"
})
})));
var projectionStage = new BsonDocument("$project",
new BsonDocument
{
{ "_id", 0 },
{ "url", 1 },
{ "description", 1 },
{ "product", 1 }
});
var stages = new BsonDocument[] {matchStage, projectionStage };
var lookupPipeline = PipelineDefinition<Image, ImageProjection>.Create(stages);
FieldDefinition <ProductOverview, List<ImageProjection>> @as = "image";
var result = await _productsCollection.Aggregate()
.Lookup<Image,ImageProjection,List<ImageProjection>,ProductOverview>(_imagesCollection, let, lookupPipeline, @as )
.ToListAsync(cancellationToken);
return result;
First question: Am I even on the right path?
Second: My lookupPipeline is null, so my PipelineDefinition doesn´t work. Is there something i didn´t notice?
Thank you, any suggestions would be greatly appreciated.