How do I check if a connection already exists

33 views
Skip to first unread message

Aneesh P U

unread,
Jun 3, 2014, 11:26:39 PM6/3/14
to clojure...@googlegroups.com
Hi, 

I am writing a web application that uses compojure and monger 2.0.0-rc1.

I have learnt that I should only be connecting to mongodb once and not on every request. 
So I need to be able to share this connection across different requests. Is there any recommendation on how I could check if a connection is already established ?

Thanks,
Aneesh



Michael Klishin

unread,
Jun 14, 2014, 5:03:34 PM6/14/14
to Monger, a Clojure MongoDB driver

2014-06-04 7:26 GMT+04:00 Aneesh P U <anee...@gmail.com>:
I have learnt that I should only be connecting to mongodb once and not on every request. 
So I need to be able to share this connection across different requests. Is there any recommendation on how I could check if a connection is already established ?

You probably want to store your connection somewhere, since in 2.0 connection is a required argument.

I recommend using Component but you can also store a connection in a var and check if it's bound with clojure.core/bound?.
--
MK

http://github.com/michaelklishin
http://twitter.com/michaelklishin
Reply all
Reply to author
Forward
0 new messages