The officially supported Ruby driver for MongoDB.
Note: You are viewing the 2.x version of the MongoDB Ruby driver which is currently unreleased and under heavy development. To view the current stable version of driver, please use the 1.x-stable branch.
Gem Installation
The Ruby driver is released and distributed through RubyGems and it can be installed with the following command:
gem install mongo
Github Installation
For development and test environments (not recommended for production) you can also install the Ruby driver directly from source:
# clone the repository
git clone https://github.com/mongodb/mongo-ruby-driver.git
cd mongo-ruby-driver
# checkout a specific version by tag (optional)
git checkout 2.x.x
# install all development dependencies
gem install bundler
bundle install
# install the ruby driver
rake install
Here is a quick example of basic usage for the Ruby driver:
require 'mongo'
# connecting to the database
client = Mongo::Client.new # defaults to localhost:27017
db = client['example-db']
coll = db['example-collection']
# inserting documents
10.times { |i| coll.insert({ :count => i+1 }) }
# finding documents
puts "There are #{coll.count} total documents. Here they are:"
coll.find.each { |doc| puts doc.inspect }
# updating documents
coll.update({ :count => 5 }, { :count => 'foobar' })
# removing documents
coll.remove({ :count => 8 })
coll.remove
For many more usage examples and a full tutorial, please visit our wiki.
For API reference documentation, please visit here.
The MongoDB Ruby driver requires Ruby 1.8.7 or greater and is regularly tested against the platforms and environments listed below.
Ruby Platforms | Operating Systems | Architectures |
---|---|---|
MRI 1.9.3, 2.0.0, 2.1.0 JRuby 1.7.x Rubinius 2.x |
Windows Linux OS X |
x86 x64 ARM |
For issues, questions or feedback related to the Ruby driver, please look into our support channels. Please do not email any of the Ruby developers directly with issues or questions - you're more likely to get an answer quickly on the mongodb-user list on Google Groups.
Do you have a bug to report or a feature request to make?
- Visit our issue tracker and login (or create an account if necessary).
- Navigate to the RUBY project.
- Click 'Create Issue' and fill out all the applicable form fields.
When reporting an issue, please keep in mind that all information in JIRA for all driver projects (ex. RUBY, CSHARP, JAVA) and the Core Server (ex. SERVER) project is PUBLICLY visible.
PLEASE DO
- Provide as much information as possible about the issue.
- Provide detailed steps for reproducing the issue.
- Provide any applicable code snippets, stack traces and log data.
- Specify version information for the driver and MongoDB.
PLEASE DO NOT
- Provide any sensitive data or server logs.
- Report potential security issues publicly (see 'Security Issues').
If you’ve identified a potential security related issue in a driver or any other MongoDB project, please report it by following the instructions here.
Full release notes and release history are available here.
Copyright (C) 2009-2013 MongoDB, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.