Golang mongodb聚合primitive.E中的值太多

Golang mongodb聚合primitive.E中的值太多,mongodb,go,aggregation-framework,aggregation,Mongodb,Go,Aggregation Framework,Aggregation,我想做一个mongo聚合 我在MongoDB中进行了以下查询: db.mongo.aggregate([{$group: {_id: {"host":"$host"}, "last_exec": {$last: "$time"}, "status": {$last: "$status"}}}]); 我使用包:go.mongodb.org 我想在Golang的代码中实现它: g

我想做一个mongo聚合
我在MongoDB中进行了以下查询:

db.mongo.aggregate([{$group: {_id: {"host":"$host"}, "last_exec": {$last: "$time"}, "status": {$last: "$status"}}}]);
我使用包:go.mongodb.org
我想在Golang的代码中实现它:

groupStage := bson.D{{"$group", bson.D{{"_id", bson.D {{"host", "$host"}}, "last_exec", bson.D{{"$last", "$time"}}, "status", bson.D{{"$last", "$status"}}}}}}
cursor, err = collection.Aggregate(ctx, mongo.Pipeline{groupStage})
if err != nil {
    fmt.Println("Failed to Aggregate: ", err)
}
if err = cursor.All(ctx, &metas); err != nil {
    fmt.Printf("cursor.All() error:", err)
}
当我运行程序时,它返回以下错误:

too many values in primitive.E{...}
有人知道如何解决这个问题吗?
谢谢你的帮助

您可以在
groupStage
中尝试此代码(它对我有效):


谢谢你,这很有效!
groupStage := bson.D{{"$group", bson.D{{"_id", bson.D{{"host", "$host"}}}, {"last_exec", bson.D{{"$last","$time"}}}}}}