mongodb - 在 Elixir 中启动 2 个 MongoDB 连接
问题描述
我正在制作一个需要同时连接到 2 个 mongo 数据库的应用程序。
我正在使用 mongodb (v0.4) 模块。
现在我的主管看起来像这样:
children=[
worker(Mongo, [[name: :mongo, database: "transit", seeds: ["localhost:27017"], pool: DBConnection.Pool]])
]
opts= [strategy: :one_for_one, name: HugoEtl.Supervisor]
Supervisor.start_link(children, opts)
我想同时打开另一个连接以将数据从一个连接泵送到另一个连接。
我怎样才能做到这一点。
解决方案
可能会阻止一个人天真地并行打开 2 个连接的是与等效模块名称相对应的工作人员的自动 ID。
children=[
worker(Mongo, [[name: :mongo, database: "transit", seeds: ["localhost:27017"], pool: DBConnection.Pool]]),
worker(Mongo, [[name: :mongo_final, database: "final", seeds: ["localhost:27017"], pool: DBConnection.Pool]], id: MongoFinal)
]
opts= [strategy: :one_for_one, name: HugoEtl.Supervisor]
Supervisor.start_link(children, opts)
这将启动 2 个数据库连接,您可以使用以下命令查询每个连接:
# first connection
Mongo.find(:mongo,"collection",%{})
# second connection
Mongo.find(:mongo_final,"collection",%{})
推荐阅读
- sql-server - 如何在 XML SQL SERVER 中转义单引号
- c - 动态分配指针数组(K&R 练习 5-13)
- python - 需要将有关人员的信息存储在文件中并提取特定信息(python)
- python - 如何使用 python 3 在 for 循环中创建新数组?
- json - 将 Shopify API 与 Google Sheet FetchUrl 应用程序一起使用
- command-line - ng:尽管安装了@angular/cli,但找不到命令
- angular - 如何更改谷歌地图中的地图类型ID以及如何删除工具提示
- amazon-web-services - 使用gzip压缩卸载时如何卸载csv文件类型?
- azure - 从 U-SQL 引用 ADL 存储 gen2 文件
- vue.js - vue.js + element-ui 对话框中的表单验证规则