Ruby Language Center

This is an overview of the available tools and suggested practices for using Ruby with MongoDB. Those wishing to skip to more detailed discussion should check out the Ruby Driver Tutorial, Rails - Getting Started, and MongoDB Data Modeling and Rails. There are also a number of good external resources worth checking out.

Ruby Driver

Install the C extension for any performance-critical applications.

The MongoDB Ruby driver is the 10gen-supported driver for MongoDB. It's written in pure Ruby, with a recommended C extension for speed. The driver is optimized for simplicity. It can be used on its own, but it also serves as the basis for various object-mapping libraries.

Installing / Upgrading

The ruby driver uses Gemcutter for gem hosting. Before installing the driver, make sure you've installed Gemcutter:

$ gem install gemcutter
$ gem tumble

Once you've added the Gemcutter repository, you can install or upgrade like so:

$ gem install mongo

To stay on the bleeding edge, check out the latest source from github:

$ git clone git://github.com/mongodb/mongo-ruby-driver.git
$ cd mongo-ruby-driver/

Then, install the driver from there:

$ rake gem:install

C Extension

There's a separate gem containing optional, but recommended, C extensions that significantly increase driver performance. To use the extensions just install the mongo_ext gem:

$ gem install mongo_ext

Or, to install from source:

$ rake gem:install_extensions

As long it's in Ruby's load path, mongo_ext will be loaded automatically when you require mongo. To learn more about the Ruby driver, see the Ruby Tutorial .

Object Mappers

If you need validations, associations, and other high-level data modeling functions, consider using one of the available object mappers. Many of these exist in the Ruby ecosystem; here we host a list of the most popular ones.

Notable Projects

Tools for working with MongoDB in Ruby are being developed daily. A partial list can eb found in the Projects and Libraries section of our external resources page.

If you're working on a project that you'd like to have included, let us know.


Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Comments (1)

IF YOU HAVE A QUESTION, POST IT TO THE USER GROUP.

These pages are fine for comments, but for questions, your best bet will always be the MongoDB User Group.

 
  1. Feb 01

    Anonymous says:

    The Ruby Reflector - MongoDB - News about Ruby and MondoDB.

    The Ruby Reflector - MongoDB - News about Ruby and MondoDB.

Add Comment