我有Mongo(GO)的Collection ,类型是:
type CreateFeedbackRequest struct {
UserID string `json:"user_id" validate:"required"`
WaybillID uint64 `json:"waybill_id" validate:"required"`
Rating int `json:"rating" validate:"required"`
Comment string `json:"comment"`
ReceivedAt time.Time `json:"received_at" validate:"required"`
}
我需要判断最近5个记录的评级中值(由receivedAt
个时间段)为某些用户(由他的user_id
).
我已经得到了这个:
matchStage := bson.D{{"$match", bson.D{{"_id", userID}}}}
sortStage := bson.D{{"$sort", bson.D{{"created_at", 1}}}}
limitStage := bson.D{{"$limit", tripsCount}}
cursor, err := r.c.Aggregate(ctx, mongo.Pipeline{matchStage, sortStage, limitStage})
但我不知道怎么才能得到这5排的评分中值.我不确定我做这件事的正确方式.帮帮忙,谢谢