Setting up MongoDB with Autoparts

Last Updated on: 15 September 2013

This guide walks through how you can setup a MongoDB database on your Nitrous.IO box.

Prerequisites

  • Nitrous.IO box with the package manager Autoparts installed. To ensure Autoparts is installed, run the command parts within the terminal. Take a look at the Autoparts guide for installation instructions.

Installing MongoDB

To install MongoDB with the autoparts package manager, run the following command:

parts install mongodb

Configuring MongoDB for a Rails App

Before making configuration, start up MongoDB with the following command:

parts start mongodb

When building a Rails app, run the following command to skip active record and test unit:

rails new myapp --skip-active-record --skip-test-unit

Rails 4 requires the latest version of mongoid, which also includs bson_ext as a dependency. Add the following lines to your Gemfile:

gem 'mongoid', git: 'https://github.com/mongoid/mongoid.git'
gem 'bson_ext'

Once the Gemfile has been updated, run the following:

bundle install

Next, generate the configuration:

rails g mongoid:config

If you are wanting to connect to an external database, please view the guide on Connecting to MongoLabs.