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
2. Install bundle
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.