MongoDB – mgo库(Golang)- 多个插入/更新

huangapple go评论85阅读模式
英文:

MongoDB - mgo library (Golang) - Multiple insert/updates

问题

Collection struct中是否有一种方法可以像Insert方法一样使用Upsert方法来处理多个文档?我想一次性插入/更新多个文档以进行优化。查看了mgo API http://godoc.org/labix.org/v2/mgo,但没有找到相关方法。

英文:

Is there a way in the Collection struct to use Upsert method for multiple documents as it is with the Insert method? I would like to insert/update many documents at once for optimization purposes. Looking at the mgo API http://godoc.org/labix.org/v2/mgo I didn't find a way.

答案1

得分: 3

不,那是不可能的。

如果你想提高连接利用率,你可以生成一些 goroutine,并在同一个会话上并发执行多个 upsert 操作。它们会独立地阻塞和接收结果,但它们会同时将请求排队到服务器。

英文:

No, that's not possible.

What you can do if you want to improve the connection utilization is to spawn a few goroutines and execute multiple upserts concurrently on the same session. They'll all block and receive results independently, but they'll all queue the requests to the server concurrently.

huangapple
  • 本文由 发表于 2013年11月6日 18:54:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/19810176.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定