mongodbclojuremonger

MongoDB Connection Pattern using Monger


I am new to clojure.

Are there any idioms/patterns around connecting to mongodb through monger?

Do I have to connect and disconnect using

(monger.core/connect) & (monger.core/disconnect conn)

respectively. each time ?

Is there a way I can reuse a connection from a connection pool?


Solution

  • monger uses MongoClient, which does connection pooling. After you connect, you can keep working with that pool until you're done, and then disconnect. See the monger documentation for supported connection options (e.g. maximum number of connections in the pool, default 10).