pax_global_header 0000666 0000000 0000000 00000000064 12212007274 0014507 g ustar 00root root 0000000 0000000 52 comment=52d0b1802c4e01ecb8d3e043d0a31bd3cbbc7d59
ruby-mongo-1.9.2/ 0000775 0000000 0000000 00000000000 12212007274 0013616 5 ustar 00root root 0000000 0000000 ruby-mongo-1.9.2/LICENSE 0000664 0000000 0000000 00000025015 12212007274 0014626 0 ustar 00root root 0000000 0000000 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
Copyright (C) 2008-2013 10gen, 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.
ruby-mongo-1.9.2/README.md 0000664 0000000 0000000 00000030315 12212007274 0015077 0 ustar 00root root 0000000 0000000 # Build Status
[travis-img]: https://travis-ci.org/mongodb/mongo-ruby-driver.png?branch=1.x-stable
[travis-url]: http://travis-ci.org/mongodb/mongo-ruby-driver
[jenkins-img]: https://jenkins.10gen.com/job/mongo-ruby-driver-1.x-stable/badge/icon
[jenkins-url]: https://jenkins.10gen.com/job/mongo-ruby-driver-1.x-stable/
[api-url]: http://api.mongodb.org/ruby/current
- TravisCI [![Travis Status][travis-img]][travis-url]
- Jenkins [![Jenkins Status][jenkins-img]][jenkins-url]
# Documentation
This API documentation is available online at [http://api.mongodb.org/ruby](http://api.mongodb.org/ruby)
for all releases of the MongoDB Ruby driver. Please reference the exact version of the documentation
that matches the release of the Ruby driver that you are using. Note that the
[Ruby Language Center for MongoDB](http://www.mongodb.org/display/DOCS/Ruby+Language+Center)
has a link to API Documentation for the current release.
If you have the source, you can generate the matching documentation by typing
```sh
$ rake docs
```
Once generated, the API documentation can be found in the docs/ folder.
# Introduction
This is the 10gen-supported Ruby driver for [MongoDB](http://www.mongodb.org).
For the api reference please see the [API][api-url]
The [wiki](https://github.com/mongodb/mongo-ruby-driver/wiki) has other articles of interest, including:
1. [A tutorial](https://github.com/mongodb/mongo-ruby-driver/wiki/Tutorial).
2. [Replica Sets in Ruby](https://github.com/mongodb/mongo-ruby-driver/wiki/Replica-Sets).
3. [Write Concern in Ruby](https://github.com/mongodb/mongo-ruby-driver/wiki/Write-Concern).
4. [Tailable Cursors in Ruby](https://github.com/mongodb/mongo-ruby-driver/wiki/Tailable-Cursors).
5. [Read Preference in Ruby](https://github.com/mongodb/mongo-ruby-driver/wiki/Read-Preference).
6. [GridFS in Ruby](https://github.com/mongodb/mongo-ruby-driver/wiki/GridFS).
7. [Frequently Asked Questions](https://github.com/mongodb/mongo-ruby-driver/wiki/FAQ).
8. [History](https://github.com/mongodb/mongo-ruby-driver/wiki/History).
9. [Release plan](https://github.com/mongodb/mongo-ruby-driver/wiki/Releases).
10. [Credits](https://github.com/mongodb/mongo-ruby-driver/wiki/Credits).
Here's a quick code sample. Again, see the [MongoDB Ruby Tutorial](https://github.com/mongodb/mongo-ruby-driver/wiki/Tutorial) for much more:
```ruby
require 'rubygems'
require 'mongo'
include Mongo
@client = MongoClient.new('localhost', 27017)
@db = @client['sample-db']
@coll = @db['test']
@coll.remove
3.times do |i|
@coll.insert({'a' => i+1})
end
puts "There are #{@coll.count} records. Here they are:"
@coll.find.each { |doc| puts doc.inspect }
```
# Installation
### Ruby Versions
The driver works and is consistently tested on Ruby 1.8.7 and 1.9.3 as well as JRuby 1.6.x and 1.7.x.
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.
### Gems
```sh
$ gem update --system
$ gem install mongo
```
For a significant performance boost, you'll want to install the C extension:
```sh
$ gem install bson_ext
```
Note that bson_ext isn't used with JRuby. Instead, we use some native Java extensions are bundled with the bson gem. If you ever need to modify these extensions, you can recompile with the following rake task:
```sh
$ rake compile:jbson
```
### From the GitHub source
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.
Once you have the source, you can use it from wherever you downloaded it or
you can install it as a gem from the source by typing:
```sh
$ rake install
```
# Examples
For extensive examples, see the [MongoDB Ruby Tutorial](https://github.com/mongodb/mongo-ruby-driver/wiki/Tutorial).
# GridFS
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
specification. GridFileSystem is essentially the same, but provides a more filesystem-like API and assumes that filenames are unique.
An instance of both classes represents an individual file store. See the API reference for details.
Examples:
```ruby
# Write a file on disk to the Grid
file = File.open('image.jpg')
grid = Mongo::Grid.new(db)
id = grid.put(file)
# Retrieve the file
file = grid.get(id)
file.read
# Get all the file's metata
file.filename
file.content_type
file.metadata
```
# Notes
## Thread Safety
The driver is thread-safe.
## Connection Pooling
The driver implements connection pooling. By default, only one
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
timeout for waiting for old connections to be released to the pool.
To set up a pooled connection to a single MongoDB instance:
```ruby
@client = MongoClient.new("localhost", 27017, :pool_size => 5, :pool_timeout => 5)
```
Though the pooling architecture will undoubtedly evolve, it currently owes much credit
to the connection pooling implementations in ActiveRecord and PyMongo.
## Forking
Certain Ruby application servers work by forking, and it has long been necessary to
re-establish the child process's connection to the database after fork. But with the release
of v1.3.0, the Ruby driver detects forking and reconnects automatically.
## Environment variable `MONGODB_URI`
`Mongo::MongoClient.from_uri`, `Mongo::MongoClient.new` and `Mongo::MongoReplicaSetClient.new` will use ENV["MONGODB_URI"]
if no other args are provided.
The URI must fit this specification:
mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
If the type of connection (direct or replica set) should be determined entirely from ENV["MONGODB_URI"]
, you may want to use `Mongo::MongoClient.from_uri` because it will return either `Mongo::MongoClient` or a `Mongo::MongoReplicaSetClient` depending on how many hosts are specified. Trying to use `Mongo::MongoClient.new` with multiple hosts in ENV["MONGODB_URI"]
will raise an exception.
## String Encoding
The BSON ("Binary JSON") format used to communicate with Mongo requires that
strings be UTF-8 (http://en.wikipedia.org/wiki/UTF-8).
Ruby 1.9 has built-in character encoding support. All strings sent to Mongo
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.
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
UTF-8. If the string is not ASCII, it may not be a well-formed UTF-8
string.
## Primary Keys
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
any type. The database itself inserts an _id value if none is specified when
a record is inserted.
### Primary Key Factories
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,
using a PK factory lets you do so.
You can tell the Ruby Mongo driver how to create primary keys by passing in
the :pk option to the MongoClient#db method.
```ruby
include Mongo
db = MongoClient.new('localhost', 27017).db('dbname', :pk => MyPKFactory.new)
```
A primary key factory object must respond to :create_pk, which should
take a hash and return a hash which merges the original hash with any
primary key fields the factory wishes to inject.
NOTE: if the object already has a primary key, the factory should not
inject a new key; this means that the object may already exist in the
database. The idea here is that whenever a record is inserted, the
:pk object's +create_pk+ method will be called and the new hash
returned will be inserted.
Here is a sample primary key factory, taken from the tests:
```ruby
class TestPKFactory
def create_pk(doc)
doc['_id'] ||= BSON::ObjectId.new
doc
end
end
```
Here's a slightly more sophisticated one that handles both symbol and string
keys. This is the PKFactory that comes with the MongoRecord code (an
ActiveRecord-like framework for non-Rails apps) and the AR Mongo adapter code
(for Rails):
```ruby
class PKFactory
def create_pk(doc)
return doc if doc[:_id]
doc.delete(:_id) # in case it exists but the value is nil
doc['_id'] ||= BSON::ObjectId.new
doc
end
end
```
A database's PK factory object may be set either when a DB object is created
or immediately after you obtain it, but only once. The only reason it is
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
for the first time.
## The DB Class
### Strict mode
_**NOTE:** Support for strict mode has been deprecated and will be removed in version 2.0 of the driver._
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
create a collection that already exists. Note that both these operations are
completely harmless; strict mode is a programmer convenience only.
To turn on strict mode, either pass in :strict => true when obtaining a DB
object or call the `:strict=` method:
```ruby
db = MongoClient.new('localhost', 27017).db('dbname', :strict => true)
# I'm feeling lax
db.strict = false
# No, I'm not!
db.strict = true
```
The method DB#strict? returns the current value of that flag.
## Cursors
Notes:
* Cursors are enumerable (and have a #to_a method).
* The query doesn't get run until you actually attempt to retrieve data from a
cursor.
* 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.
## Socket timeouts
The Ruby driver support timeouts on socket read operations. To enable them, set the
`:op_timeout` option when you create a `Mongo::MongoClient` object.
If implementing higher-level timeouts, using tools like `Rack::Timeout`, it's very important
to call `Mongo::MongoClient#close` to prevent the subsequent operation from receiving the previous
request.
# Testing
Before running the tests, make sure you install all test dependencies by running:
```sh
$ gem install bundler; bundle install
```
To run all default test suites (without the BSON extensions) just type:
```sh
$ rake test
```
If you want to run the default test suite using the BSON extensions:
```sh
$ rake test:ext
```
These will run both unit and functional tests. To run these tests alone:
```sh
$ rake test:unit
$ rake test:functional
```
To run any individual rake tasks with the BSON extension disabled, just pass BSON_EXT_DISABLED=true to the task:
```sh
$ rake test:unit BSON_EXT_DISABLED=true
```
If you want to test replica set, you can run the following task:
```sh
$ rake test:replica_set
```
To run a single test at the top level, add -Itest since we no longer modify LOAD_PATH:
```sh
$ ruby -Itest -Ilib test/bson/bson_test.rb
```
To run a single test from the test directory, add -I. since we no longer modify LOAD_PATH:
```sh
$ ruby -I. -I../lib bson/bson_test.rb
```
To run a single test from its subdirectory, add -I.. since we no longer modify LOAD_PATH:
```sh
$ ruby -I.. -I../../lib bson_test.rb
```
To fix the following error on Mac OS X - "/.../lib/bson_ext/cbson.bundle: [BUG] Segmentation fault":
```sh
$ rake compile
```
# Release Notes
See [history](https://github.com/mongodb/mongo-ruby-driver/wiki/History).
# Credits
See [credits](https://github.com/mongodb/mongo-ruby-driver/wiki/Credits).
# License
Copyright (C) 2008-2013 10gen 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.
ruby-mongo-1.9.2/Rakefile 0000664 0000000 0000000 00000001741 12212007274 0015266 0 ustar 00root root 0000000 0000000 # Copyright (C) 2013 10gen 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.
require 'rubygems'
begin
require 'bundler'
rescue LoadError
raise '[FAIL] Bundler not found! Install it with `gem install bundler; bundle install`.'
end
if ENV.has_key?('TEST') || ENV.has_key?('TRAVIS_TEST')
Bundler.require(:default, :testing)
else
Bundler.require(:default, :testing, :deploy, :development)
end
Dir.glob(File.join('tasks', '**', '*.rake')).sort.each { |rake| load File.expand_path(rake) } ruby-mongo-1.9.2/VERSION 0000664 0000000 0000000 00000000005 12212007274 0014661 0 ustar 00root root 0000000 0000000 1.9.2 ruby-mongo-1.9.2/bin/ 0000775 0000000 0000000 00000000000 12212007274 0014366 5 ustar 00root root 0000000 0000000 ruby-mongo-1.9.2/bin/mongo_console 0000775 0000000 0000000 00000002201 12212007274 0017150 0 ustar 00root root 0000000 0000000 #!/usr/bin/env ruby
# Copyright (C) 2013 10gen 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.
org_argv = ARGV.dup
ARGV.clear
require 'irb'
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
include Mongo
host = org_argv[0] || ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = org_argv[1] || ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
dbnm = org_argv[2] || ENV['MONGO_RUBY_DRIVER_DB'] || 'ruby-mongo-console'
puts "Connecting to #{host}:#{port} (CLIENT) on with database #{dbnm} (DB)"
CLIENT = MongoClient.new(host, port)
DB = CLIENT.db(dbnm)
puts "Starting IRB session..."
IRB.start(__FILE__)
ruby-mongo-1.9.2/checksums.yaml.gz 0000664 0000000 0000000 00000000413 12212007274 0017104 0 ustar 00root root 0000000 0000000 YRe;n0"HЭ[ 0tRedw._~^~^X3Rle
WvR8OTt4QPOǣU^z@5{IÂe&{.( 6ک7(/N01ѹNPg=Ԧ!sX`yֽ<@ReH^Y%j.iVgɭ8CRwe#ddH3͢FM1zڤ/:
ruby-mongo-1.9.2/checksums.yaml.gz.sig 0000664 0000000 0000000 00000000400 12212007274 0017661 0 ustar 00root root 0000000 0000000 1hkz!G=Oʢ /_
Ld? J_C8(@+#
-=5ՃTliG
#E鑸