Install and use mongodb with rails

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 keyserver.ubuntu.com –recv 7F0CEB10

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

and add this into bottom line :
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart 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”, “>= 3.0.1”

2. Install bundle
bundle install
Alternatively you can get the Mongoid gem direcly from rubygems.org:
$ 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.

One thought on “Install and use mongodb with rails

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s