Mongoid : bson namespace error

Hello All,

I had been trying to work on Rails 4 and Mongoid gem.

The following are the versions I had installed:

bson-2.2.1

mongoid-3.1.6

After installing and trying to run “rails generate” command. It is failing with NameSpace error for BSON::ByteBuffer.

It is trying to connect to mongodb server initially and getting successful. Post that it is failing with the following error

rails generate

C:/Ruby193/lib/ruby/gems/1.9.1/gems/mongo-1.9.2/lib/mongo/cursor.rb:585:in `construct_query_message’: uninitialized constant BSON::ByteBuffer (NameError)

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mongo-1.9.2/lib/mongo/cursor.rb:497:in `block in send_initial_query’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mongo-1.9.2/lib/mongo/util/logging.rb:55:in `block in instrument’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mongo-1.9.2/lib/mongo/util/logging.rb:20:in `instrument’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mongo-1.9.2/lib/mongo/util/logging.rb:54:in `instrument’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mongo-1.9.2/lib/mongo/cursor.rb:495:in `send_initial_query’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mongo-1.9.2/lib/mongo/cursor.rb:480:in `refresh’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mongo-1.9.2/lib/mongo/cursor.rb:126:in `next’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mongo-1.9.2/lib/mongo/db.rb:564:in `command’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mongo-1.9.2/lib/mongo/mongo_client.rb:585:in `block in check_is_master’

from C:/Ruby193/lib/ruby/1.9.1/timeout.rb:69:in `timeout’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mongo-1.9.2/lib/mongo/mongo_client.rb:584:in `check_is_master’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mongo-1.9.2/lib/mongo/mongo_client.rb:468:in `connect’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mongo-1.9.2/lib/mongo/mongo_client.rb:693:in `setup’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mongo-1.9.2/lib/mongo/mongo_client.rb:155:in `initialize’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mongo-1.9.2/lib/mongo/legacy.rb:52:in `initialize’

from C:/MyWork/CopperHundi/config/initializers/mongo.rb:3:in `new’

from C:/MyWork/CopperHundi/config/initializers/mongo.rb:3:in `<top (required)>’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/engine.rb:609:in `block (2 levels) in class:Engine

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/engine.rb:608:in `each’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/engine.rb:608:in `block in class:Engine

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `instance_exec’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `run’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/initializable.rb:55:in `block in run_initializers’

from C:/Ruby193/lib/ruby/1.9.1/tsort.rb:150:in `block in tsort_each’

from C:/Ruby193/lib/ruby/1.9.1/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component’

from C:/Ruby193/lib/ruby/1.9.1/tsort.rb:210:in `block (2 levels) in each_strongly_connected_component_from’

from C:/Ruby193/lib/ruby/1.9.1/tsort.rb:219:in `each_strongly_connected_component_from’

from C:/Ruby193/lib/ruby/1.9.1/tsort.rb:209:in `block in each_strongly_connected_component_from’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/initializable.rb:44:in `each’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/initializable.rb:44:in `tsort_each_child’

from C:/Ruby193/lib/ruby/1.9.1/tsort.rb:203:in `each_strongly_connected_component_from’

from C:/Ruby193/lib/ruby/1.9.1/tsort.rb:182:in `block in each_strongly_connected_component’

from C:/Ruby193/lib/ruby/1.9.1/tsort.rb:180:in `each’

from C:/Ruby193/lib/ruby/1.9.1/tsort.rb:180:in `each_strongly_connected_component’

from C:/Ruby193/lib/ruby/1.9.1/tsort.rb:148:in `tsort_each’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/initializable.rb:54:in `run_initializers’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/application.rb:215:in `initialize!’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:30:in `method_missing’

from C:/MyWork/CopperHundi/config/environment.rb:5:in `<top (required)>’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/application.rb:189:in `require’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/application.rb:189:in `require_environment!’

from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/commands.rb:44:in `<top (required)>’

from bin/rails:4:in `require’

from bin/rails:4:in `’

I tried referring to few articles on namespace, checked to see if loading problem and scope of the bson getting loaded.

Any further help on how to debug this issue would help me proceed further.

Thank you

Best Wishes,
Saideep Annadatha

Hello All,

I had been trying to work on Rails 4 and Mongoid gem.

The following are the versions I had installed:

bson-2.2.1

mongoid-3.1.6

After installing and trying to run “rails generate” command. It is failing with NameSpace error for BSON::ByteBuffer.

The mongoid gem does not use the mongo gem (they mongoid guys decided to implement their own driver called moped).

At a guess it looks like you’ve got all of these in your gemfile. Also it looks like the mongo 1.9.2 gem needs an earlier version of the bson gem than the one you say you’re using- not sure how that got past bundler. Anyway, given that you shouldn’t need the mongo gem I’d start by removing it and any use of it you’ve made

Fred

That worked.!! Thank you Fred.