Mongoid infinite loop on query Mongoid infinite loop on query heroku heroku

Mongoid infinite loop on query


I had a similar problem with MongoLab, with infinite DB queries until I hit a stack level too deep. My client wanted a free DB, so I stuck with troubleshooting for a good 12 hours.

I tried everything above, as well as some other config options and then stumbled across this:https://devcenter.heroku.com/articles/mongolab

There is a line in there that I had overlooked: "If you’re using MongoDB version 3.0 (all MongoLab Sandboxes are version 3.0), you must use Mongoid 5.x. ". I had run a bundle update, so I didn't think much of it.

You should go in your gemfile and specify:

gem 'mongoid', '~> 5.0'

I also had to delete my mongoid.yml and start over with

rails g mongoid:config

mongoid.yml changes its nesting to list "clients" instead of "sessions", which really confuses Rails.

That's what fixed it for me.


It looks (from your DB username) we are both using MongoHQ addon for Heroku, their lowest tier databases are sharded and I believe there's a simple config change needed to help the query route correctly once it's arrived.

# Force a the driver cluster to behave in a certain manner instead of auto- # discovering. Can be one of: :direct, :replica_set, :sharded. Set to :direct # when connecting to hidden members of a replica set. connect: :direct

http://docs.mongodb.org/ecosystem/tutorial/ruby-mongoid-tutorial/#anatomy-of-a-mongoid-config

I changed to Mongo Compose addon which isn't sharded and the problem disappeared immediately.

If you want to persist with MongoLab, which has the free version try tinkering with the config like:

options:   connect: :sharded

Further reading: http://docs.mongodb.org/manual/core/sharded-cluster-query-router/#broadcast-operations