我有以下代码: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知道我哪里出错了吗?
- 1 回答
- 0 关注
- 182 浏览
添加回答
举报
0/150
提交
取消