mgo 有序排序聚合

mgo Ordered Sort Aggregation

我有以下代码:

competitionMatch := bson.M{ "$match": bson.M{"competition" : bson.M{"$in" : []string{"PREMIERSHIP", "CHAMPIONSHIP", "LEAGUE1", "LEAGUE2"}}}}

group := bson.M{"$group" : bson.M{"_id" : "$homeTeam", "competitionOrder": bson.M{"$max": "$competitionOrder"}, "competition": bson.M{"$max" : "$competition"}}}
//sort := bson.M{"$sort" : bson.M{"competitionOrder": 1,"_id": 1}}
sort := bson.M{"$sort" : bson.D{{"competitionOrder", 1}, {"_id",1}}}
project := bson.M{"$project" : bson.M{"_id":1, "competitionOrder":1, "competition": 1}}

pipe := sessionCopy.DB("footballrecord").C(season).Pipe([]bson.M{competitionMatch, group, sort, project})

我正在尝试进行排序。评论的 sort 有效,但是 bson.M 它是无序的,有时查询没有返回我期望的结果。

我正在尝试使用 bson.D(未注释的行),但当查询为 运行 时出现以下错误: the $sort key specification must be an object

知道我哪里出错了吗?

我发现这是 godep 的问题。导入语句没有被重写。