MongoDB.NET驱动程序:使用第一个累加器分组
是否可以使用.NET驱动程序2.2对聚合管道中的$first累加器进行分组 我正在尝试使用驱动程序编写以下查询:MongoDB.NET驱动程序:使用第一个累加器分组,mongodb,mongodb-query,mongodb-.net-driver,Mongodb,Mongodb Query,Mongodb .net Driver,是否可以使用.NET驱动程序2.2对聚合管道中的$first累加器进行分组 我正在尝试使用驱动程序编写以下查询: db.collection.aggregate( [ { $sort : { "createdDate" : -1 } }, { $group : { _id : "$key", latestEntity :
db.collection.aggregate(
[
{
$sort : { "createdDate" : -1 }
},
{
$group : {
_id : "$key",
latestEntity : { $first : "$$ROOT" }
}
}
]
.NET:
系统.NotSupportException与“不支持指定的方法”一起引发。当前不支持$$ROOT特殊变量。。。如果您愿意,请在CSHARP项目下的jira.mongodb.org上提交特性请求。
var result = collection
.Aggregate()
.SortByDescending(x => x.CreatedDate)
.Group(k => k.Key, x => x.First())
.ToList();