minor: update README and convert to markdown
This commit is contained in:
parent
54a3cbb308
commit
70be27a262
|
@ -1,10 +1,9 @@
|
||||||
= Introduction
|
# Introduction
|
||||||
|
|
||||||
This is the 10gen-supported Ruby driver for MongoDB[http://www.mongodb.org].
|
This is the 10gen-supported Ruby driver for [MongoDB](http://www.mongodb.org).
|
||||||
|
|
||||||
Here's a quick code sample. See the MongoDB Ruby Tutorial
|
|
||||||
(http://www.mongodb.org/display/DOCS/Ruby+Tutorial) for much more:
|
|
||||||
|
|
||||||
|
Here's a quick code sample. See the [MongoDB Ruby Tutorial](http://www.mongodb.org/display/DOCS/Ruby+Tutorial)
|
||||||
|
for much more:
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'mongo'
|
require 'mongo'
|
||||||
|
@ -20,19 +19,18 @@ Here's a quick code sample. See the MongoDB Ruby Tutorial
|
||||||
puts "There are #{coll.count()} records. Here they are:"
|
puts "There are #{coll.count()} records. Here they are:"
|
||||||
coll.find().each { |doc| puts doc.inspect }
|
coll.find().each { |doc| puts doc.inspect }
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
|
||||||
= Installation
|
### Ruby Versions
|
||||||
|
|
||||||
=== Ruby Versions
|
|
||||||
|
|
||||||
The driver works and is consistently tested on Ruby 1.8.6, 1.8.7, and 1.9.2, and JRuby 1.5.1.
|
The driver works and is consistently tested on Ruby 1.8.6, 1.8.7, and 1.9.2, and JRuby 1.5.1.
|
||||||
|
|
||||||
Note that if you're on 1.8.7, be sure that you're using a patchlevel >= 249. There
|
Note that if you're on 1.8.7, be sure that you're using a patchlevel >= 249. There
|
||||||
are some IO bugs in earlier versions.
|
are some IO bugs in earlier versions.
|
||||||
|
|
||||||
=== Gems
|
### Gems
|
||||||
|
|
||||||
The driver's gems are hosted at Rubygems.org[http://rubygems.org]. Make sure you're
|
The driver's gems are hosted at [Rubygems.org](http://rubygems.org). Make sure you're
|
||||||
using the latest version of rubygems:
|
using the latest version of rubygems:
|
||||||
|
|
||||||
$ gem update --system
|
$ gem update --system
|
||||||
|
@ -54,7 +52,7 @@ If you ever need to modify these extenions, you can recompile with the following
|
||||||
|
|
||||||
$ rake build:java
|
$ rake build:java
|
||||||
|
|
||||||
=== From the GitHub source
|
### From the GitHub source
|
||||||
|
|
||||||
The source code is available at http://github.com/mongodb/mongo-ruby-driver.
|
The source code is available at http://github.com/mongodb/mongo-ruby-driver.
|
||||||
You can either clone the git repository or download a tarball or zip file.
|
You can either clone the git repository or download a tarball or zip file.
|
||||||
|
@ -69,10 +67,9 @@ To install the C extensions from source, type this instead:
|
||||||
|
|
||||||
That's all there is to it!
|
That's all there is to it!
|
||||||
|
|
||||||
= Examples
|
# Examples
|
||||||
|
|
||||||
For extensive examples, see the MongoDB Ruby Tutorial
|
For extensive examples, see the [MongoDB Ruby Tutorial](http://www.mongodb.org/display/DOCS/Ruby+Tutorial).
|
||||||
(http://www.mongodb.org/display/DOCS/Ruby+Tutorial).
|
|
||||||
|
|
||||||
Bundled with the driver are many examples, located in the "examples" subdirectory. Samples include using
|
Bundled with the driver are many examples, located in the "examples" subdirectory. Samples include using
|
||||||
the driver and using the GridFS class GridStore. MongoDB must be running for
|
the driver and using the GridFS class GridStore. MongoDB must be running for
|
||||||
|
@ -88,10 +85,7 @@ Here's how to start MongoDB and run the "simple.rb" example:
|
||||||
|
|
||||||
See also the test code, especially test/test_db_api.rb.
|
See also the test code, especially test/test_db_api.rb.
|
||||||
|
|
||||||
= GridFS
|
# GridFS
|
||||||
|
|
||||||
Note: The GridStore class has been deprecated. Use either the Grid or GridFileSystem
|
|
||||||
classes to take advantage of GridFS.
|
|
||||||
|
|
||||||
The Ruby driver include two abstractions for storing large files: Grid and GridFileSystem.
|
The Ruby driver include two abstractions for storing large files: Grid and GridFileSystem.
|
||||||
The Grid class is a Ruby implementation of MongoDB's GridFS file storage
|
The Grid class is a Ruby implementation of MongoDB's GridFS file storage
|
||||||
|
@ -103,23 +97,6 @@ for details, and see examples/gridfs.rb for code that uses many of the Grid
|
||||||
features (metadata, content type, seek, tell, etc).
|
features (metadata, content type, seek, tell, etc).
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
include Mongo
|
|
||||||
|
|
||||||
# Get a database
|
|
||||||
db = Mongo::Connection.new.db('app-db')
|
|
||||||
|
|
||||||
# GridFileSystem. Store the text "Hello, world!" in the fs.
|
|
||||||
fs = GridFileSystem.new(db)
|
|
||||||
fs.open('filename', 'w') do |f|
|
|
||||||
f.write "Hello, world!"
|
|
||||||
end
|
|
||||||
|
|
||||||
# GridFileSystem. Output "Hello, world!"
|
|
||||||
fs = GridFileSystem.new(db)
|
|
||||||
fs.open('filename', 'r') do |f|
|
|
||||||
puts f.read
|
|
||||||
end
|
|
||||||
|
|
||||||
# Write a file on disk to the Grid
|
# Write a file on disk to the Grid
|
||||||
file = File.open('image.jpg')
|
file = File.open('image.jpg')
|
||||||
grid = Grid.new(db)
|
grid = Grid.new(db)
|
||||||
|
@ -134,15 +111,15 @@ Examples:
|
||||||
file.content_type
|
file.content_type
|
||||||
file.metadata
|
file.metadata
|
||||||
|
|
||||||
= Notes
|
# Notes
|
||||||
|
|
||||||
== Thread Safety
|
## Thread Safety
|
||||||
|
|
||||||
The driver is thread-safe.
|
The driver is thread-safe.
|
||||||
|
|
||||||
== Connection Pooling
|
## Connection Pooling
|
||||||
|
|
||||||
As of 0.18, the driver implements connection pooling. By default, only one
|
As of v0.18, the driver implements connection pooling. By default, only one
|
||||||
socket connection will be opened to MongoDB. However, if you're running a
|
socket connection will be opened to MongoDB. However, if you're running a
|
||||||
multi-threaded application, you can specify a maximum pool size and a maximum
|
multi-threaded application, you can specify a maximum pool size and a maximum
|
||||||
timeout for waiting for old connections to be released to the pool.
|
timeout for waiting for old connections to be released to the pool.
|
||||||
|
@ -151,39 +128,25 @@ To set up a pooled connection to a single MongoDB instance:
|
||||||
|
|
||||||
@conn = Connection.new("localhost", 27017, :pool_size => 5, :timeout => 5)
|
@conn = Connection.new("localhost", 27017, :pool_size => 5, :timeout => 5)
|
||||||
|
|
||||||
A pooled connection to a paired instance would look like this:
|
|
||||||
|
|
||||||
@conn = Connection.new({:left => ["db1.example.com", 27017],
|
|
||||||
:right => ["db2.example.com", 27017]}, nil,
|
|
||||||
:pool_size => 20, :timeout => 5)
|
|
||||||
|
|
||||||
Though the pooling architecture will undoubtedly evolve, it currently owes much credit
|
Though the pooling architecture will undoubtedly evolve, it currently owes much credit
|
||||||
to the connection pooling implementations in ActiveRecord and PyMongo.
|
to the connection pooling implementations in ActiveRecord and PyMongo.
|
||||||
|
|
||||||
== Using with Phusion Passenger
|
## Using with Phusion Passenger and Unicorn
|
||||||
|
|
||||||
When passenger is in smart spawning mode you need to be sure that child
|
When Passenger and Unicorn are in smart spawning mode you need to be sure that child
|
||||||
processes forked by passenger will create a new connection to the database.
|
processes will create a new connection to the database. In Passenger, this can be handled like so:
|
||||||
activerecord-mongo-adapter handles this for you, so if you are using that
|
|
||||||
you shouldn't need to worry about it. Otherwise you'll either need to use
|
|
||||||
conservative spawning[http://www.modrails.org/documentation/Users%20guide.html#RailsSpawnMethod]
|
|
||||||
or handle reconnecting when passenger forks a new process:
|
|
||||||
|
|
||||||
if defined?(PhusionPassenger)
|
if defined?(PhusionPassenger)
|
||||||
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
||||||
if forked
|
if forked
|
||||||
# Call db.connect to reconnect here
|
# Create new connection here
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
The above code should be put in _environment.rb_ or in an initialization
|
The above code should be put into a Rails initializer or other initialization script.
|
||||||
script.
|
|
||||||
|
|
||||||
See this thread[http://groups.google.com/group/mongodb-user/browse_thread/thread/f31e2d23de38136a]
|
## String Encoding
|
||||||
for more details on this issue.
|
|
||||||
|
|
||||||
== String Encoding
|
|
||||||
|
|
||||||
The BSON ("Binary JSON") format used to communicate with Mongo requires that
|
The BSON ("Binary JSON") format used to communicate with Mongo requires that
|
||||||
strings be UTF-8 (http://en.wikipedia.org/wiki/UTF-8).
|
strings be UTF-8 (http://en.wikipedia.org/wiki/UTF-8).
|
||||||
|
@ -193,18 +156,18 @@ and received from Mongo are converted to UTF-8 when necessary, and strings
|
||||||
read from Mongo will have their character encodings set to UTF-8.
|
read from Mongo will have their character encodings set to UTF-8.
|
||||||
|
|
||||||
When used with Ruby 1.8, the bytes in each string are written to and read from
|
When used with Ruby 1.8, the bytes in each string are written to and read from
|
||||||
Mongo as-is. If the string is ASCII all is well, because ASCII is a subset of
|
Mongo as is. If the string is ASCII, all is well, because ASCII is a subset of
|
||||||
UTF-8. If the string is not ASCII, it may not be a well-formed UTF-8
|
UTF-8. If the string is not ASCII, it may not be a well-formed UTF-8
|
||||||
string.
|
string.
|
||||||
|
|
||||||
== Primary Keys
|
## Primary Keys
|
||||||
|
|
||||||
The field _id is a primary key. It is treated specially by the database, and
|
The `_id` field is a primary key. It is treated specially by the database, and
|
||||||
its use makes many operations more efficient. The value of an _id may be of
|
its use makes many operations more efficient. The value of an _id may be of
|
||||||
any type. The database itself inserts an _id value if none is specified when
|
any type. The database itself inserts an _id value if none is specified when
|
||||||
a record is inserted.
|
a record is inserted.
|
||||||
|
|
||||||
=== Primary Key Factories
|
### Primary Key Factories
|
||||||
|
|
||||||
A primary key factory is a class you supply to a DB object that knows how to
|
A primary key factory is a class you supply to a DB object that knows how to
|
||||||
generate _id values. If you want to control _id values or even their types,
|
generate _id values. If you want to control _id values or even their types,
|
||||||
|
@ -254,13 +217,9 @@ changeable at all is so that libraries such as MongoRecord that use this
|
||||||
driver can set the PK factory after obtaining the database but before using it
|
driver can set the PK factory after obtaining the database but before using it
|
||||||
for the first time.
|
for the first time.
|
||||||
|
|
||||||
== The DB Class
|
## The DB Class
|
||||||
|
|
||||||
=== Primary Key factories
|
### Strict mode
|
||||||
|
|
||||||
See the section on "Primary Keys" above.
|
|
||||||
|
|
||||||
=== Strict mode
|
|
||||||
|
|
||||||
Each database has an optional strict mode. If strict mode is on, then asking
|
Each database has an optional strict mode. If strict mode is on, then asking
|
||||||
for a collection that does not exist will raise an error, as will asking to
|
for a collection that does not exist will raise an error, as will asking to
|
||||||
|
@ -268,7 +227,7 @@ create a collection that already exists. Note that both these operations are
|
||||||
completely harmless; strict mode is a programmer convenience only.
|
completely harmless; strict mode is a programmer convenience only.
|
||||||
|
|
||||||
To turn on strict mode, either pass in :strict => true when obtaining a DB
|
To turn on strict mode, either pass in :strict => true when obtaining a DB
|
||||||
object or call the :strict= method:
|
object or call the `:strict=` method:
|
||||||
|
|
||||||
db = Connection.new.db('dbname', :strict => true)
|
db = Connection.new.db('dbname', :strict => true)
|
||||||
# I'm feeling lax
|
# I'm feeling lax
|
||||||
|
@ -278,26 +237,26 @@ object or call the :strict= method:
|
||||||
|
|
||||||
The method DB#strict? returns the current value of that flag.
|
The method DB#strict? returns the current value of that flag.
|
||||||
|
|
||||||
== Cursors
|
## Cursors
|
||||||
|
|
||||||
Random cursor fun facts:
|
Notes:
|
||||||
|
|
||||||
- Cursors are enumerable.
|
* Cursors are enumerable (and have a #to_a method).
|
||||||
|
|
||||||
- The query doesn't get run until you actually attempt to retrieve data from a
|
* The query doesn't get run until you actually attempt to retrieve data from a
|
||||||
cursor.
|
cursor.
|
||||||
|
|
||||||
- Cursors have a to_a method.
|
* Cursors will timeout on the server after 10 minutes. If you need to keep a cursor
|
||||||
|
open for more than 10 minutes, specify `:timeout => false` when you create the cursor.
|
||||||
|
|
||||||
|
|
||||||
= Testing
|
# Testing
|
||||||
|
|
||||||
If you have the source code, you can run the tests. There's a separate rake task for testing with
|
If you have the source code, you can run the tests.
|
||||||
the bson_ext C extension enabled.
|
|
||||||
|
|
||||||
$ rake test:c
|
$ rake test:c
|
||||||
|
|
||||||
If you want to test the basic Ruby encoder, or if you're running JRuby:
|
If you want to test the basic Ruby encoder, without the C extension, or if you're running JRuby:
|
||||||
|
|
||||||
$ rake test:ruby
|
$ rake test:ruby
|
||||||
|
|
||||||
|
@ -310,18 +269,14 @@ To run any individual rake tasks with the C extension enabled, just pass C_EXT=t
|
||||||
|
|
||||||
$ rake test:unit C_EXT=true
|
$ rake test:unit C_EXT=true
|
||||||
|
|
||||||
If you want to test replica pairs, you can run the following tests
|
If you want to test replica set, you can run the following tests
|
||||||
individually:
|
individually:
|
||||||
|
|
||||||
$ rake test:pair_count
|
$ rake test:replica_set_count
|
||||||
$ rake test:pair_insert
|
$ rake test:replica_set_insert
|
||||||
$ rake test:pair_query
|
$ rake test:replica_set_query
|
||||||
|
|
||||||
It's also possible to test replica pairs with connection pooling:
|
### Shoulda and Mocha
|
||||||
|
|
||||||
$ rake test:pooled_pair_insert
|
|
||||||
|
|
||||||
===Shoulda and Mocha
|
|
||||||
|
|
||||||
Running the test suite requires shoulda and mocha. You can install them as follows:
|
Running the test suite requires shoulda and mocha. You can install them as follows:
|
||||||
|
|
||||||
|
@ -333,25 +288,24 @@ can override the default host (localhost) and port (Connection::DEFAULT_PORT) by
|
||||||
using the environment variables MONGO_RUBY_DRIVER_HOST and
|
using the environment variables MONGO_RUBY_DRIVER_HOST and
|
||||||
MONGO_RUBY_DRIVER_PORT.
|
MONGO_RUBY_DRIVER_PORT.
|
||||||
|
|
||||||
= Documentation
|
# Documentation
|
||||||
|
|
||||||
This documentation is available online at http://api.mongodb.org/ruby. You can
|
This documentation is available online at [http://api.mongodb.org/ruby](http://api.mongodb.org/ruby). You can
|
||||||
generate the documentation if you have the source by typing
|
generate the documentation if you have the source by typing
|
||||||
|
|
||||||
$ rake ydoc
|
$ rake ydoc
|
||||||
|
|
||||||
Then open the file +ydoc/index.html+.
|
Then open the file +ydoc/index.html+.
|
||||||
|
|
||||||
|
# Release Notes
|
||||||
= Release Notes
|
|
||||||
|
|
||||||
See HISTORY.
|
See HISTORY.
|
||||||
|
|
||||||
= Credits
|
# Credits
|
||||||
|
|
||||||
See CREDITS.
|
See CREDITS.
|
||||||
|
|
||||||
= License
|
# License
|
||||||
|
|
||||||
Copyright 2008-2010 10gen Inc.
|
Copyright 2008-2010 10gen Inc.
|
||||||
|
|
|
@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
||||||
|
|
||||||
s.require_paths = ['lib']
|
s.require_paths = ['lib']
|
||||||
|
|
||||||
s.files = ['README.rdoc', 'HISTORY', 'Rakefile',
|
s.files = ['README.md', 'HISTORY', 'Rakefile',
|
||||||
'mongo.gemspec', 'LICENSE.txt']
|
'mongo.gemspec', 'LICENSE.txt']
|
||||||
s.files += ['lib/mongo.rb'] + Dir['lib/mongo/**/*.rb']
|
s.files += ['lib/mongo.rb'] + Dir['lib/mongo/**/*.rb']
|
||||||
s.files += Dir['examples/**/*.rb'] + Dir['bin/**/*.rb']
|
s.files += Dir['examples/**/*.rb'] + Dir['bin/**/*.rb']
|
||||||
|
@ -25,8 +25,8 @@ Gem::Specification.new do |s|
|
||||||
s.test_files -= Dir['test/mongo_bson/*.rb'] # remove these files from the manifest
|
s.test_files -= Dir['test/mongo_bson/*.rb'] # remove these files from the manifest
|
||||||
|
|
||||||
s.has_rdoc = true
|
s.has_rdoc = true
|
||||||
s.rdoc_options = ['--main', 'README.rdoc', '--inline-source']
|
s.rdoc_options = ['--main', 'README.md', '--inline-source']
|
||||||
s.extra_rdoc_files = ['README.rdoc']
|
s.extra_rdoc_files = ['README.md']
|
||||||
|
|
||||||
s.authors = ['Jim Menard', 'Mike Dirolf', 'Kyle Banker']
|
s.authors = ['Jim Menard', 'Mike Dirolf', 'Kyle Banker']
|
||||||
s.email = 'mongodb-dev@googlegroups.com'
|
s.email = 'mongodb-dev@googlegroups.com'
|
||||||
|
|
Loading…
Reference in New Issue