Database Reference
In-Depth Information
New to Ruby?
Ruby is a popular and readable scripting language. The code examples have been
designed to be as explicit as possible, so that even programmers unfamiliar with
Ruby can benefit. Any Ruby idioms that may be hard to understand will be explained
in the text. If you'd like to spend a few minutes getting up to speed with Ruby, start
with the official 20-minute tutorial at http://mng.bz/ T HR3 .
with MongoDB. Without getting too low-level, this section will show you what's going
on behind the scenes with the drivers in general. Finally, you'll develop a simple Ruby
application for monitoring Twitter. Working with a real-world data set, you'll begin to
see how MongoDB works in the wild. This final section will also lay the groundwork
for the more in-depth examples presented in part 2.
3.1
MongoDB through the Ruby lens
Normally when you think of drivers, what come to mind are low-level bit manipula-
tions and obtuse interfaces. Thankfully, the MongoDB language drivers are nothing
like that; instead, they've been designed with intuitive, language-sensitive API s, so that
many applications can sanely use a MongoDB driver as the sole interface to the data-
base. The driver API s are also fairly consistent across languages, which means that
developers can easily move between languages as needed. If you're an application
developer, you can expect to find yourself comfortable and productive with any of the
MongoDB drivers without having to concern yourself with low-level implementation
details.
In this first section, you'll install the MongoDB Ruby driver, connect to the data-
base, and learn how to perform basic CRUD operations. This will lay the groundwork
for the application you'll build at the end of the chapter.
3.1.1
Installing and connecting
You can install the MongoDB Ruby driver using RubyGems, Ruby's package manage-
ment system.
NOTE If you don't have Ruby installed on your system, you can find detailed
installation instructions at http://www.ruby-lang.org/en/downloads/ . You'll
also need Ruby's package manager, RubyGems. Instructions for installing
RubyGems can be found at http://docs.rubygems.org/read/chapter/3 .
gem install mongo
This should install both the mongo and bson 1 gems. You should see output like the fol-
lowing (the version numbers will likely be newer that what's shown here):
1
BSON, which is explained in the next section, is the JSON-inspired binary format that MongoDB uses to rep-
resent documents. The bson Ruby gem serializes Ruby objects to and from BSON.
 
Search WWH ::




Custom Search