rdo
rdo

Reputation: 3982

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 connection 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.

Upvotes: 0

Views: 222

Answers (1)

Adam Lindberg
Adam Lindberg

Reputation: 16577

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.

Upvotes: 1

Related Questions