Ruby on Rails and MongoDB

1.9k Views Asked by At

I have a new Ruby on Rails installation where I can see the default start-page.

I followed this guide in order to install MongoDB to Rails.

Now I get this error when running rake test:

**Notice: C extension not loaded. This is required for optimum MongoDB Ruby driver performance.
  You can install the extension as follows:
  gem install bson_ext

  If you continue to receive this message after installing, make sure that the
  bson_ext gem is in your load path and that the bson_ext and mongo gems are of the same version.

I have installed the bson_ext gem, which means that now bson_ext in not in my load path or that the gems are not the same version.

Where is the load path? How can I change it? How do I check if the gems are the same version?

2

There are 2 best solutions below

4
On BEST ANSWER

If you're using Ruby on Rails 3+, you should check that the bson_ext gem is referenced in your Gemfile.

1
On

Open up Gemfile (in your rails app's root directory) and add a line that says: bson_ext

You should have:

gem mongo
gem bson_ext

Also here is some more info from 10gen docs on running tests in rails:

Running Tests A slight modification is required to get rake test working (thanks to John P. Wood). Create a file lib/tasks/mongo.rake containing the following:

namespace :db do
  namespace :test do
    task :prepare do
      # Stub out for MongoDB
    end
  end
end

Now the various rake test tasks will run properly. See John's post for more details.

They also reference John Wood's post which is quite good.