Using the ruby mongodb driver, is there a way I can create a connection object in the configure block that can be accessed in the route methods so that I don’t have to recreate the connection on each request?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Set a global variable in a configuration block:
or stick it in
settings:I must say that I find neither of these very elegant.
When developing in may look as if the connection is created on every request, but start your server in production and you will see that it behaves differently (for example,
thin -e production).Also, if your app will run under Passenger, you need to do this:
What it does is that it reconnects to the database after Passenger forks, so that child processes have their own connection. Not doing this will give you really strange errors.