0
内の式のように定義する必要があります -集計フィールドをC#にMongoDBの集計クエリ下のポートしようとしているが、エラーになっオブジェクトエラー
コマンド集約に失敗しました: 定義されなければならないグループの集計フィールド「で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