Search code examples
rubymongoidmongoid4

Mongoid how to set timeout


Mongoid can't connect to a remote MongoLab database from my machine, which I assume is due to network latency cause it works on the remote server.

From MongoLab (http://docs.mongolab.com/connecting/#help).

For network latency and security reasons, we strongly recommend that you always connect to your database from the same datacenter that your application is located in.

Well I want to do it anyway. Is there a way to change just the timeout, something like (fake code):

Mongoid.configure do |config|
  config.timeout = 5000 # ms
end

Solution

  • You can set the timeout value in the Mongoid YAML file. Here's an example: https://github.com/mongolab/mongodb-driver-examples/blob/master/ruby/mongoid3/mongoid.yml