有人知道我们在 mongodb shell 中用于 golang mgo/bson 的 aggregate 命令的等价物是什么吗?
类似的东西:
aggregate([{$match:{my_id:ObjectId("543d171c5b2c1242fe0019")}},{$sort:{my_id:1, dateInfo:1, name:1}},{$group:{_id:"$my_id", lastEntry:{$max: "$dateInfo"},nm:{$last:"$name"}}}])
最佳答案
假设 c
是您的收藏:
pipe := c.Pipe([]bson.M{{"$match": bson.M{"name":"John"}}})
resp := []bson.M{}
err := pipe.All(&resp)
if err != nil {
//handle error
}
fmt.Println(resp) // simple print proving it's working
GoDoc 引用:
关于mongodb - Mongodb 的 Golang mgo 聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26456375/