英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论