如何将此mongoDb聚合用于C#
我想提出一个具体的问题。 如何在mongoDb中为C#使用相同的聚合如何将此mongoDb聚合用于C#,c#,asp.net-mvc,mongodb,C#,Asp.net Mvc,Mongodb,我想提出一个具体的问题。 如何在mongoDb中为C#使用相同的聚合 这可以使用MongoDB compass工具轻松实现 请参阅如何实现以下结果 using MongoDB.Bson; using MongoDB.Driver; new BsonArray { new BsonDocument("$project", new BsonDocument { { "_id", 1 }, { "personalDat
这可以使用MongoDB compass工具轻松实现 请参阅如何实现以下结果
using MongoDB.Bson;
using MongoDB.Driver;
new BsonArray
{
new BsonDocument("$project",
new BsonDocument
{
{ "_id", 1 },
{ "personalData", 1 },
{ "Dependentsbenefits",
new BsonDocument("$filter",
new BsonDocument
{
{ "input", "$Dependentsbenefits" },
{ "as", "depend" },
{ "cond",
new BsonDocument("$eq",
new BsonArray
{
"$$depend.dependentId",
"70b39bed-e3e0-41e3-a5be-076623b9a909"
}) }
}) }
})
}
如何使用此数据在Mongo中使用C#进行查询?这是为聚合查询生成的C#代码_employee.Aggregate()+上面的代码
using MongoDB.Bson;
using MongoDB.Driver;
new BsonArray
{
new BsonDocument("$project",
new BsonDocument
{
{ "_id", 1 },
{ "personalData", 1 },
{ "Dependentsbenefits",
new BsonDocument("$filter",
new BsonDocument
{
{ "input", "$Dependentsbenefits" },
{ "as", "depend" },
{ "cond",
new BsonDocument("$eq",
new BsonArray
{
"$$depend.dependentId",
"70b39bed-e3e0-41e3-a5be-076623b9a909"
}) }
}) }
})
}