1

I have a library I was working on have left it for a while, when I went back to work on it, it's still fine but when I updated gems: mongoid from 2.4.5 to 3.0.6 and also updated mongo and bson_ext from 1.6.0 to 1.7.0 and when run my rspec I get error

<top (required)>': uninitialized constant Mongo (NameError) from

Mongoid.configure do |config|
  config.master = Mongo::Connection.new.db("db_test")
end

I have: ruby 1.9.3p125 mongodb 2.0.2-x86_64

This one has the same problem Mongoid gives uninitialized constant Mongo but the solution didn't work for me.

Adding require "mongo" on mine gives a different error:

spec_helper.rb:11:in 'block in <top (required)>': undefined method 'master=' for Mongoid::Config:Module (NoMethodError)

EDIT I still used 3.x and this is now how they do connections

Mongoid.configure do |config|
  config.connect_to("db_test")
end
Community
  • 1
  • 1
index
  • 3,697
  • 7
  • 36
  • 55

1 Answers1

1

Mongoid 3.x does not use the mongo gem anymore, it uses a driver called moped developed by the Mongoid team.

If you want to stick with the official 10gen driver you would need to update your Gemfile to specify you want to stick with Mongoid 2.x:

gem "mongoid", "~> 2.0"
Tyler Brock
  • 29,626
  • 15
  • 79
  • 79
  • Oh really? Haha! Stupid me. Thanks for that. Didn't noticed and man do I need to check their changes. So umn, I still want to use 3.x - does my problem translate to this one here http://mongoid.org/en/moped/docs/driver.html ? – index Sep 22 '12 at 00:18
  • Yeah, sorry. I'm not really sure where your link points cause the part after the ? got cut off. – Tyler Brock Sep 23 '12 at 22:09
  • That's an actual question mark. Ehe. But here's a better link I think http://mongoid.org/en/moped/docs/driver.html#behaviour . I haven't tried it yet, still haven't gone back to my work station. – index Sep 24 '12 at 06:25
  • Ok, well the interface of mongoid itself changes very little as it wraps the driver. If you want to use mongoid it should be similar but you need to just update your configuration. See this: http://mongoid.org/en/mongoid/docs/installation.html#configuration – Tyler Brock Sep 24 '12 at 13:36