0
试图下面mongodb的聚合查询端口到c#,但得到的错误内的表达 -骨料字段必须被定义为对象错误
命令骨料失败:组聚集字段“ProductType”必须 被定义作为对象内的表达式。
有关C#代码有什么问题的任何想法?
db.collectionName.aggregate([
{ $match: activeTrial},
{ $project: {_id:1, CustomerType: 1, ProductType: 1} },
{ $group: {_id: {"cust": "$CustomerType", "prod" : "$ProductType"}, count: {$sum: 1}}},
]).toArray()
collectionName.Aggregate()
.Match(filter)
.Project(x => new {x.CustomerType, x.SubscriptionId, x.ProductType})
.Group(x => new { x.ProductType, x.CustomerType }, g => new ActiveTrialsByProduct()
{
ProductType = g.Key.ProductType,
CustomerType = g.Key.CustomerType,
ActiveTrials = g.Count()
}).ToList();
这里是集..
{
"CustomerType" : "CustA",
"ProductType" : "ProdA",
}
{
"CustomerType" : "CustA",
"ProductType" : "ProdB",
}
{
"CustomerType" : "CustA",
"ProductType" : "ProdB",
}
{
"CustomerType" : "CustA",
"ProductType" : "ProdA",
}
请提供样本数据。这应该有助于重现错误。 – AxxE
@AxxE更新了样本数据。谢谢。 – GBackMania