开发者

How to use db in erlang correctly?

I write some example on erlang and mongodb. As driver for mongodb I use emongo. Problem is if I make connection in one module I can not reuse this conn开发者_运维百科ection in different modules. In C/C++ or other objective languages I can make singleton and use it. How can I reuse open connection in erlang? Thanks.


You should be able to re-use the pool ID from any part of your application.

In module A:

emongo:insert(test, SomeCollection, Document).

In module B:

emongo:insert(test, AnotherCollection, AnotherDocument).

As long as you keep using the same id (in this case, test) either by hard coding it into the different modules or by sending it in a message, you should be able to use the library from any part of the application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜