2 回答

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超5個(gè)贊
假設(shè)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貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超10個(gè)贊
示例代碼:
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)
注意:
請(qǐng)注意,該行應(yīng)與(,)如果你不打破(,),它會(huì)拋出錯(cuò)誤消息,即使您的查詢是正確的結(jié)束。
輸出:
{
"transactions": [
{
"_id": "three@four.com",
"count": 10
},
{
"_id": "one@two.com",
"count": 12
}
]
}
- 2 回答
- 0 關(guān)注
- 231 瀏覽
添加回答
舉報(bào)