2 回答

TA贡献1772条经验 获得超5个赞
假设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

TA贡献1815条经验 获得超10个赞
示例代码:
pipe := c.Pipe([]bson.M{bson.M{"$match": bson.M{"type": "stamp"}},
bson.M{"$group": bson.M{"_id": "$userid",
"count": bson.M{"$sum": "$noofsr"}}}})
resp := []bson.M{}
iter := pipe.Iter()
err = iter.All(&resp)
注意:
请注意,该行应与(,)如果你不打破(,),它会抛出错误消息,即使您的查询是正确的结束。
输出:
{
"transactions": [
{
"_id": "three@four.com",
"count": 10
},
{
"_id": "one@two.com",
"count": 12
}
]
}
- 2 回答
- 0 关注
- 206 浏览
添加回答
举报