在upsert中使用mgo聚合迭代器数据而无需拆封

First of all, I am very new to go :)

I am trying to do an aggregate + upsert in mongo using go and mgo driver.

My code looks something like this:

pipe := c.Pipe([]bson.M{{"$match": bson.M{"name":"John"}}})
iter := pipe.Iter()
resp := []bson.M{}

for iter.Next(&resp) {
     //
     // read "value.sha1" from each response
     // do a:
     // otherCollection.Upsert(bson.M{"value.sha1": mySha1}, resp)
     //
}

The response from the aggregate collection can have lot's of formats, so I can't define a struct for it.

I just need to get one of the fields from the response, which is a sha1, and update another collection with the response received, based on the sha1 condition.

Can anybody point me in the right direction?

查看全部
du16178
du16178
2016/07/23 09:45
  • mongodb
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复