在 Elixir 中开始 2 MongoDB 个连接

Start 2 MongoDB connections in Elixir

我正在制作一个需要同时连接到 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 个连接的是对应于等效模块名称的 worker 的自动 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",%{})