Install and use mongoDB with Rails in Ubuntu

MongoDB is a scalable, high-performance, document-oriented schemaless database. In this post I describe how to install MongoDB in ubuntu 12.04 and how to use mongobd with rails.

Followings are the steps to install MongoDB

1. Add GPG Key
sudo apt-key adv –keyserver –recv 7F0CEB10

2. Edit your source.list
sudo gedit /etc/apt/sources.list

and add this into bottom line :
deb dist 10gen

3. Update and install
sudo apt-get update
sudo apt-get install mongodb-10gen

After installing the MongoDB, you have to install and use mongoid gem to use MongoDB with rails. Followings are the steps to use mongoid gem with rails.

1. Add following code in your gem file
gem “mongoid”

2. Install bundle
bundle install
Alternatively you can get the Mongoid gem direcly from
$ gem install mongoid

3. Generate mongoid.yml
You can generate a config file by executing the generator and then editing myapp/config/mongoid.yml to your heart’s desire. Mongoid will then handle everything else from there.
$ rails g mongoid:config

Now your application support mongodb as database.


Leave a Reply

Your email address will not be published. Required fields are marked *

Enter Captcha Here : *

Reload Image