Ruby MongoDB Driver

This is an overview of the available tools and suggested practices for using Ruby with MongoDB. To skip to more detailed discussion see:

For a list of external resources, see Ruby External Resources.

Ruby Driver

The MongoDB Ruby driver is the officially supported Ruby driver for MongoDB. It’s written in pure Ruby and is optimized for simplicity. It can be used on its own, but it also serves as the basis of several object mapping libraries, such as Mongoid.



The Ruby BSON implementation is packaged in a separate gem with C and Java extensions for speed depending on the runtime enviroment.


Object Mappers

Because MongoDB is so easy to use, the basic Ruby driver can be the best solution for many applications.

But if you need validations, associations, and other high-level data modeling functions then an Object Document Mapper may be needed.

In the context of a Rails application these provide functionality equivalent to, but distinct from, ActiveRecord. Because MongoDB is a document-based database, these mappers are called Object Document Mappers (ODM) as opposed to Object Relational Mappers (ORM).

Several mappers are available:

All the mappers build on top of the basic Ruby driver and so some knowledge of that is useful, especially if you work with a custom MongoDB configuration.

Notable Projects

Tools for working with MongoDB in Ruby are being developed daily. See Ruby External Resources.

If you are working on a project that you would like to have included, let us know.