Mongodb c# Driver 2.4 的聚合无法正常工作

Aggregation with Mongodb c# Driver 2.4 not working

使用如下命令时,返回null。

        var pipeline = new BsonDocument[] {
            new BsonDocument{{"$group", new BsonDocument{{"_id", "$BrandId"}}}}
        };

        var brands = context
            .Items.Aggregate<BsonDocument>(pipeline);

数据示例:

我的聚合方法如下图:

似乎您所缺少的只是在 Aggregate() 调用后执行 ToList() 或 ToListAsync() 以使其成为 return 数据。

您没有使用 Group 方法的原因是什么?

Aggregate().Group(new BsonDocument() { "_id" : "$BrandId"})