What is the alternate of aggregate $set under MongoDB.Driver fluent API?

Ved_Singhal
Mon, 07 Nov 2022 04:38:28 +0000

Could someone please help me in finding alternate of aggregate $set under MongoDB.Driver fluent API?

I want am in need of converting this logic to using fluent API

From –
BsonDocument pipelineStage1 = new BsonDocument{
{
“$set”, new BsonDocument{
{
“ProjectId1”, new BsonDocument{
{ “$toObjectId”, “$ProjectId” }
}
}
}
}
};
BsonDocument pipelineStage2 = new BsonDocument{
{
“$lookup”, new BsonDocument{
{ “from”, “projects” },
{ “localField”, “ProjectId1” },
{ “foreignField”, “_id” },
{ “as”, “Project” }
}
}
};
BsonDocument pipeline = new BsonDocument {
pipelineStage1,
pipelineStage2
};
var aggregationResult = _collection
.Aggregate(pipeline)
.ToList();

To –
var aggregationQuery = _collection
.Aggregate()
.As();
//this is where I need to convert of of the fiend into object id using set.
foreach (var lookup in lookups)
{
aggregationQuery = aggregationQuery
.Lookup(lookup.foreignCollectionName, lookup.localField, lookup.foreignField, @as: lookup.@as)
.As();
}

I appreciate your help.

Read full topic