mongo 1.3.0 → 1.12.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +122 -271
- data/Rakefile +25 -209
- data/VERSION +1 -0
- data/bin/mongo_console +31 -9
- data/lib/mongo/bulk_write_collection_view.rb +387 -0
- data/lib/mongo/collection.rb +576 -269
- data/lib/mongo/collection_writer.rb +364 -0
- data/lib/mongo/connection/node.rb +249 -0
- data/lib/mongo/connection/pool.rb +340 -0
- data/lib/mongo/connection/pool_manager.rb +320 -0
- data/lib/mongo/connection/sharding_pool_manager.rb +67 -0
- data/lib/mongo/connection/socket/socket_util.rb +37 -0
- data/lib/mongo/connection/socket/ssl_socket.rb +95 -0
- data/lib/mongo/connection/socket/tcp_socket.rb +87 -0
- data/lib/mongo/connection/socket/unix_socket.rb +39 -0
- data/lib/mongo/connection/socket.rb +18 -0
- data/lib/mongo/connection.rb +7 -875
- data/lib/mongo/cursor.rb +403 -117
- data/lib/mongo/db.rb +444 -243
- data/lib/mongo/exception.rb +145 -0
- data/lib/mongo/functional/authentication.rb +455 -0
- data/lib/mongo/functional/logging.rb +85 -0
- data/lib/mongo/functional/read_preference.rb +183 -0
- data/lib/mongo/functional/scram.rb +556 -0
- data/lib/mongo/functional/uri_parser.rb +409 -0
- data/lib/mongo/functional/write_concern.rb +66 -0
- data/lib/mongo/functional.rb +20 -0
- data/lib/mongo/gridfs/grid.rb +30 -24
- data/lib/mongo/gridfs/grid_ext.rb +6 -10
- data/lib/mongo/gridfs/grid_file_system.rb +38 -20
- data/lib/mongo/gridfs/grid_io.rb +84 -75
- data/lib/mongo/gridfs.rb +18 -0
- data/lib/mongo/legacy.rb +140 -0
- data/lib/mongo/mongo_client.rb +697 -0
- data/lib/mongo/mongo_replica_set_client.rb +535 -0
- data/lib/mongo/mongo_sharded_client.rb +159 -0
- data/lib/mongo/networking.rb +372 -0
- data/lib/mongo/{util → utils}/conversions.rb +29 -8
- data/lib/mongo/{util → utils}/core_ext.rb +28 -18
- data/lib/mongo/{util → utils}/server_version.rb +4 -6
- data/lib/mongo/{util → utils}/support.rb +29 -31
- data/lib/mongo/utils/thread_local_variable_manager.rb +25 -0
- data/lib/mongo/utils.rb +19 -0
- data/lib/mongo.rb +51 -50
- data/mongo.gemspec +29 -32
- data/test/functional/authentication_test.rb +39 -0
- data/test/functional/bulk_api_stress_test.rb +133 -0
- data/test/functional/bulk_write_collection_view_test.rb +1198 -0
- data/test/functional/client_test.rb +627 -0
- data/test/functional/collection_test.rb +2175 -0
- data/test/functional/collection_writer_test.rb +83 -0
- data/test/{conversions_test.rb → functional/conversions_test.rb} +47 -3
- data/test/functional/cursor_fail_test.rb +57 -0
- data/test/functional/cursor_message_test.rb +56 -0
- data/test/functional/cursor_test.rb +683 -0
- data/test/functional/db_api_test.rb +835 -0
- data/test/functional/db_connection_test.rb +25 -0
- data/test/functional/db_test.rb +348 -0
- data/test/functional/grid_file_system_test.rb +285 -0
- data/test/{grid_io_test.rb → functional/grid_io_test.rb} +72 -11
- data/test/{grid_test.rb → functional/grid_test.rb} +88 -15
- data/test/functional/pool_test.rb +136 -0
- data/test/functional/safe_test.rb +98 -0
- data/test/functional/ssl_test.rb +29 -0
- data/test/functional/support_test.rb +62 -0
- data/test/functional/timeout_test.rb +60 -0
- data/test/functional/uri_test.rb +446 -0
- data/test/functional/write_concern_test.rb +118 -0
- data/test/helpers/general.rb +50 -0
- data/test/helpers/test_unit.rb +476 -0
- data/test/replica_set/authentication_test.rb +37 -0
- data/test/replica_set/basic_test.rb +189 -0
- data/test/replica_set/client_test.rb +393 -0
- data/test/replica_set/connection_test.rb +138 -0
- data/test/replica_set/count_test.rb +66 -0
- data/test/replica_set/cursor_test.rb +220 -0
- data/test/replica_set/insert_test.rb +157 -0
- data/test/replica_set/max_values_test.rb +151 -0
- data/test/replica_set/pinning_test.rb +105 -0
- data/test/replica_set/query_test.rb +73 -0
- data/test/replica_set/read_preference_test.rb +219 -0
- data/test/replica_set/refresh_test.rb +211 -0
- data/test/replica_set/replication_ack_test.rb +95 -0
- data/test/replica_set/ssl_test.rb +32 -0
- data/test/sharded_cluster/basic_test.rb +203 -0
- data/test/shared/authentication/basic_auth_shared.rb +260 -0
- data/test/shared/authentication/bulk_api_auth_shared.rb +249 -0
- data/test/shared/authentication/gssapi_shared.rb +176 -0
- data/test/shared/authentication/sasl_plain_shared.rb +96 -0
- data/test/shared/authentication/scram_shared.rb +92 -0
- data/test/shared/ssl_shared.rb +235 -0
- data/test/test_helper.rb +53 -94
- data/test/threading/basic_test.rb +120 -0
- data/test/tools/mongo_config.rb +708 -0
- data/test/tools/mongo_config_test.rb +160 -0
- data/test/unit/client_test.rb +381 -0
- data/test/unit/collection_test.rb +89 -53
- data/test/unit/connection_test.rb +282 -32
- data/test/unit/cursor_test.rb +206 -8
- data/test/unit/db_test.rb +55 -13
- data/test/unit/grid_test.rb +43 -16
- data/test/unit/mongo_sharded_client_test.rb +48 -0
- data/test/unit/node_test.rb +93 -0
- data/test/unit/pool_manager_test.rb +111 -0
- data/test/unit/read_pref_test.rb +406 -0
- data/test/unit/read_test.rb +159 -0
- data/test/unit/safe_test.rb +69 -36
- data/test/unit/sharding_pool_manager_test.rb +84 -0
- data/test/unit/write_concern_test.rb +175 -0
- data.tar.gz.sig +3 -0
- metadata +227 -216
- metadata.gz.sig +0 -0
- data/docs/CREDITS.md +0 -123
- data/docs/FAQ.md +0 -116
- data/docs/GridFS.md +0 -158
- data/docs/HISTORY.md +0 -244
- data/docs/RELEASES.md +0 -33
- data/docs/REPLICA_SETS.md +0 -72
- data/docs/TUTORIAL.md +0 -247
- data/docs/WRITE_CONCERN.md +0 -28
- data/lib/mongo/exceptions.rb +0 -71
- data/lib/mongo/gridfs/grid_io_fix.rb +0 -38
- data/lib/mongo/repl_set_connection.rb +0 -342
- data/lib/mongo/test.rb +0 -20
- data/lib/mongo/util/pool.rb +0 -177
- data/lib/mongo/util/uri_parser.rb +0 -185
- data/test/async/collection_test.rb +0 -224
- data/test/async/connection_test.rb +0 -24
- data/test/async/cursor_test.rb +0 -162
- data/test/async/worker_pool_test.rb +0 -99
- data/test/auxillary/1.4_features.rb +0 -166
- data/test/auxillary/authentication_test.rb +0 -68
- data/test/auxillary/autoreconnect_test.rb +0 -41
- data/test/auxillary/fork_test.rb +0 -30
- data/test/auxillary/repl_set_auth_test.rb +0 -58
- data/test/auxillary/slave_connection_test.rb +0 -36
- data/test/auxillary/threaded_authentication_test.rb +0 -101
- data/test/bson/binary_test.rb +0 -15
- data/test/bson/bson_test.rb +0 -649
- data/test/bson/byte_buffer_test.rb +0 -208
- data/test/bson/hash_with_indifferent_access_test.rb +0 -38
- data/test/bson/json_test.rb +0 -17
- data/test/bson/object_id_test.rb +0 -154
- data/test/bson/ordered_hash_test.rb +0 -204
- data/test/bson/timestamp_test.rb +0 -24
- data/test/collection_test.rb +0 -910
- data/test/connection_test.rb +0 -309
- data/test/cursor_fail_test.rb +0 -75
- data/test/cursor_message_test.rb +0 -43
- data/test/cursor_test.rb +0 -483
- data/test/db_api_test.rb +0 -726
- data/test/db_connection_test.rb +0 -15
- data/test/db_test.rb +0 -287
- data/test/grid_file_system_test.rb +0 -243
- data/test/load/resque/load.rb +0 -21
- data/test/load/resque/processor.rb +0 -26
- data/test/load/thin/load.rb +0 -24
- data/test/load/unicorn/load.rb +0 -23
- data/test/load/unicorn/unicorn.rb +0 -29
- data/test/replica_sets/connect_test.rb +0 -94
- data/test/replica_sets/connection_string_test.rb +0 -32
- data/test/replica_sets/count_test.rb +0 -35
- data/test/replica_sets/insert_test.rb +0 -53
- data/test/replica_sets/pooled_insert_test.rb +0 -55
- data/test/replica_sets/query_secondaries.rb +0 -96
- data/test/replica_sets/query_test.rb +0 -51
- data/test/replica_sets/replication_ack_test.rb +0 -66
- data/test/replica_sets/rs_test_helper.rb +0 -27
- data/test/safe_test.rb +0 -68
- data/test/support/hash_with_indifferent_access.rb +0 -186
- data/test/support/keys.rb +0 -45
- data/test/support_test.rb +0 -18
- data/test/threading/threading_with_large_pool_test.rb +0 -90
- data/test/threading_test.rb +0 -87
- data/test/tools/auth_repl_set_manager.rb +0 -14
- data/test/tools/load.rb +0 -58
- data/test/tools/repl_set_manager.rb +0 -266
- data/test/tools/sharding_manager.rb +0 -202
- data/test/tools/test.rb +0 -4
- data/test/unit/pool_test.rb +0 -9
- data/test/unit/repl_set_connection_test.rb +0 -59
- data/test/uri_test.rb +0 -91
data/docs/FAQ.md
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
# Ruby MongoDB FAQ
|
2
|
-
|
3
|
-
This is a list of frequently asked questions about using Ruby with MongoDB. If you have a question you'd like to have answered here, please post your question to the [mongodb-user list](http://groups.google.com/group/mongodb-user).
|
4
|
-
|
5
|
-
#### Can I run (insert command name here) from the Ruby driver?
|
6
|
-
|
7
|
-
Yes. You can run any of the [available database commands|List of Database Commands] from the driver using the DB#command method. The only trick is to use an OrderedHash when specifying the command. For example, here's how you'd run an asynchronous fsync from the driver:
|
8
|
-
|
9
|
-
|
10
|
-
# This command is run on the admin database.
|
11
|
-
@db = Mongo::Connection.new.db('admin')
|
12
|
-
|
13
|
-
# Build the command.
|
14
|
-
cmd = OrderedHash.new
|
15
|
-
cmd['fsync'] = 1
|
16
|
-
cmd['async'] = true
|
17
|
-
|
18
|
-
# Run it.
|
19
|
-
@db.command(cmd)
|
20
|
-
|
21
|
-
|
22
|
-
It's important to keep in mind that some commands, like `fsync`, must be run on the `admin` database, while other commands can be run on any database. If you're having trouble, check the [command reference|List of Database Commands] to make sure you're using the command correctly.
|
23
|
-
|
24
|
-
#### Does the Ruby driver support an EXPLAIN command?
|
25
|
-
|
26
|
-
Yes. `explain` is, technically speaking, an option sent to a query that tells MongoDB to return an explain plan rather than the query's results. You can use `explain` by constructing a query and calling explain at the end:
|
27
|
-
|
28
|
-
|
29
|
-
@collection = @db['users']
|
30
|
-
result = @collection.find({:name => "jones"}).explain
|
31
|
-
|
32
|
-
|
33
|
-
The resulting explain plan might look something like this:
|
34
|
-
|
35
|
-
|
36
|
-
{"cursor"=>"BtreeCursor name_1",
|
37
|
-
"startKey"=>{"name"=>"Jones"},
|
38
|
-
"endKey"=>{"name"=>"Jones"},
|
39
|
-
"nscanned"=>1.0,
|
40
|
-
"n"=>1,
|
41
|
-
"millis"=>0,
|
42
|
-
"oldPlan"=>{"cursor"=>"BtreeCursor name_1",
|
43
|
-
"startKey"=>{"name"=>"Jones"},
|
44
|
-
"endKey"=>{"name"=>"Jones"}
|
45
|
-
},
|
46
|
-
"allPlans"=>[{"cursor"=>"BtreeCursor name_1",
|
47
|
-
"startKey"=>{"name"=>"Jones"},
|
48
|
-
"endKey"=>{"name"=>"Jones"`]
|
49
|
-
}
|
50
|
-
|
51
|
-
|
52
|
-
Because this collection has an index on the "name" field, the query uses that index, only having to scan a single record. "n" is the number of records the query will return. "millis" is the time the query takes, in milliseconds. "oldPlan" indicates that the query optimizer has already seen this kind of query and has, therefore, saved an efficient query plan. "allPlans" shows all the plans considered for this query.
|
53
|
-
|
54
|
-
#### I see that BSON supports a symbol type. Does this mean that I can store Ruby symbols in MongoDB?
|
55
|
-
|
56
|
-
You can store Ruby symbols in MongoDB, but only as values. BSON specifies that document keys must be strings. So, for instance, you can do this:
|
57
|
-
|
58
|
-
|
59
|
-
@collection = @db['test']
|
60
|
-
|
61
|
-
boat_id = @collection.save({:vehicle => :boat})
|
62
|
-
car_id = @collection.save({"vehicle" => "car"})
|
63
|
-
|
64
|
-
@collection.find_one('_id' => boat_id)
|
65
|
-
{"_id" => ObjectID('4bb372a8238d3b5c8c000001'), "vehicle" => :boat}
|
66
|
-
|
67
|
-
|
68
|
-
@collection.find_one('_id' => car_id)
|
69
|
-
{"_id" => ObjectID('4bb372a8238d3b5c8c000002'), "vehicle" => "car"}
|
70
|
-
|
71
|
-
|
72
|
-
Notice that the symbol values are returned as expected, but that symbol keys are treated as strings.
|
73
|
-
|
74
|
-
#### Why can't I access random elements within a cursor?
|
75
|
-
|
76
|
-
MongoDB cursors are designed for sequentially iterating over a result set, and all the drivers, including the Ruby driver, stick closely to this directive. Internally, a Ruby cursor fetches results in batches by running a MongoDB `getmore` operation. The results are buffered for efficient iteration on the client-side.
|
77
|
-
|
78
|
-
What this means is that a cursor is nothing more than a device for returning a result set on a query that's been initiated on the server. Cursors are not containers for result sets. If we allow a cursor to be randomly accessed, then we run into issues regarding the freshness of the data. For instance, if I iterate over a cursor and then want to retrieve the cursor's first element, should a stored copy be returned, or should the cursor re-run the query? If we returned a stored copy, it may not be fresh. And if the the query is re-run, then we're technically dealing with a new cursor.
|
79
|
-
|
80
|
-
To avoid those issues, we're saying that anyone who needs flexible access to the results of a query should store those results in an array and then access the data as needed.
|
81
|
-
|
82
|
-
#### Why can't I save an instance of TimeWithZone?
|
83
|
-
|
84
|
-
MongoDB stores times in UTC as the number of milliseconds since the epoch. This means that the Ruby driver serializes Ruby Time objects only. While it would certainly be possible to serialize a TimeWithZone, this isn't preferable since the driver would still deserialize to a Time object.
|
85
|
-
|
86
|
-
All that said, if necessary, it'd be easy to write a thin wrapper over the driver that would store an extra time zone attribute and handle the serialization/deserialization of TimeWithZone transparently.
|
87
|
-
|
88
|
-
#### I keep getting CURSOR_NOT_FOUND exceptions. What's happening?
|
89
|
-
|
90
|
-
The most likely culprit here is that the cursor is timing out on the server. Whenever you issue a query, a cursor is created on the server. Cursor naturally time out after ten minutes, which means that if you happen to be iterating over a cursor for more than ten minutes, you risk a CURSOR_NOT_FOUND exception.
|
91
|
-
|
92
|
-
There are two solutions to this problem. You can either:
|
93
|
-
|
94
|
-
1. Limit your query. Use some combination of `limit` and `skip` to reduce the total number of query results. This will, obviously, bring down the time it takes to iterate.
|
95
|
-
|
96
|
-
2. Turn off the cursor timeout. To do that, invoke `find` with a block, and pass `:timeout => true`:
|
97
|
-
|
98
|
-
@collection.find({}, :timeout => false) do |cursor|
|
99
|
-
cursor.each do |document
|
100
|
-
# Process documents here
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
#### I periodically see connection failures between the driver and MongoDB. Why can't the driver retry the operation automatically?
|
105
|
-
|
106
|
-
A connection failure can indicate any number of failure scenarios. Has the server crashed? Are we experiencing a temporary network partition? Is there a bug in our ssh tunnel?
|
107
|
-
|
108
|
-
Without further investigation, it's impossible to know exactly what has caused the connection failure. Furthermore, when we do see a connection failure, it's impossible to know how many operations prior to the failure succeeded. Imagine, for instance, that we're using safe mode and we send an `$inc` operation to the server. It's entirely possible that the server has received the `$inc` but failed on the call to `getLastError`. In that case, retrying the operation would result in a double-increment.
|
109
|
-
|
110
|
-
Because of the indeterminacy involved, the MongoDB drivers will not retry operations on connection failure. How connection failures should be handled is entirely dependent on the application. Therefore, we leave it to the application developers to make the best decision in this case.
|
111
|
-
|
112
|
-
The drivers will reconnect on the subsequent operation.
|
113
|
-
|
114
|
-
#### I ocassionally get an error saying that responses are out of order. What's happening?
|
115
|
-
|
116
|
-
See (this JIRA issue)[http://jira.mongodb.org/browse/RUBY-221].
|
data/docs/GridFS.md
DELETED
@@ -1,158 +0,0 @@
|
|
1
|
-
# GridFS in Ruby
|
2
|
-
|
3
|
-
GridFS, which stands for "Grid File Store," is a specification for storing large files in MongoDB. It works by dividing a file into manageable chunks and storing each of those chunks as a separate document. GridFS requires two collections to achieve this: one collection stores each file's metadata (e.g., name, size, etc.) and another stores the chunks themselves. If you're interested in more details, check out the [GridFS Specification](http://www.mongodb.org/display/DOCS/GridFS+Specification).
|
4
|
-
|
5
|
-
### The Grid class
|
6
|
-
|
7
|
-
The [Grid class](Mongo/Grid.html) represents the core GridFS implementation. Grid gives you a simple file store, keyed on a unique ID. This means that duplicate filenames aren't a problem. To use the Grid class, first make sure you have a database, and then instantiate a Grid:
|
8
|
-
|
9
|
-
|
10
|
-
@db = Mongo::Connection.new.db('social_site')
|
11
|
-
@grid = Grid.new(@db)
|
12
|
-
|
13
|
-
#### Saving files
|
14
|
-
Once you have a Grid object, you can start saving data to it. The data can be either a string or an IO-like object that responds to a #read method:
|
15
|
-
|
16
|
-
|
17
|
-
# Saving string data
|
18
|
-
id = @grid.put("here's some string / binary data")
|
19
|
-
|
20
|
-
# Saving IO data and including the optional filename
|
21
|
-
image = File.open("me.jpg")
|
22
|
-
id2 = @grid.put(image, :filename => "me.jpg")
|
23
|
-
|
24
|
-
|
25
|
-
Grid#put returns an object id, which you can use to retrieve the file:
|
26
|
-
|
27
|
-
|
28
|
-
# Get the string we saved
|
29
|
-
file = @grid.get(id)
|
30
|
-
|
31
|
-
# Get the file we saved
|
32
|
-
image = @grid.get(id2)
|
33
|
-
|
34
|
-
|
35
|
-
#### File metadata
|
36
|
-
|
37
|
-
There are accessors for the various file attributes:
|
38
|
-
|
39
|
-
|
40
|
-
image.filename
|
41
|
-
# => "me.jpg"
|
42
|
-
|
43
|
-
image.content_type
|
44
|
-
# => "image/jpg"
|
45
|
-
|
46
|
-
image.file_length
|
47
|
-
# => 502357
|
48
|
-
|
49
|
-
image.upload_date
|
50
|
-
# => Mon Mar 01 16:18:30 UTC 2010
|
51
|
-
|
52
|
-
# Read all the image's data at once
|
53
|
-
image.read
|
54
|
-
|
55
|
-
# Read the first 100k bytes of the image
|
56
|
-
image.read(100 * 1024)
|
57
|
-
|
58
|
-
|
59
|
-
When putting a file, you can set many of these attributes and write arbitrary metadata:
|
60
|
-
|
61
|
-
|
62
|
-
# Saving IO data
|
63
|
-
file = File.open("me.jpg")
|
64
|
-
id2 = @grid.put(file,
|
65
|
-
:filename => "my-avatar.jpg"
|
66
|
-
:content_type => "application/jpg",
|
67
|
-
:_id => 'a-unique-id-to-use-in-lieu-of-a-random-one',
|
68
|
-
:chunk_size => 100 * 1024,
|
69
|
-
:metadata => {'description' => "taken after a game of ultimate"})
|
70
|
-
|
71
|
-
|
72
|
-
#### Safe mode
|
73
|
-
|
74
|
-
A kind of safe mode is built into the GridFS specification. When you save a file, and MD5 hash is created on the server. If you save the file in safe mode, an MD5 will be created on the client for comparison with the server version. If the two hashes don't match, an exception will be raised.
|
75
|
-
|
76
|
-
|
77
|
-
image = File.open("me.jpg")
|
78
|
-
id2 = @grid.put(image, "my-avatar.jpg", :safe => true)
|
79
|
-
|
80
|
-
|
81
|
-
#### Deleting files
|
82
|
-
|
83
|
-
Deleting a file is as simple as providing the id:
|
84
|
-
|
85
|
-
|
86
|
-
@grid.delete(id2)
|
87
|
-
|
88
|
-
|
89
|
-
### The GridFileSystem class
|
90
|
-
|
91
|
-
[GridFileSystem](http://api.mongodb.org/ruby/current/Mongo/GridFileSystem.html) is a light emulation of a file system and therefore has a couple of unique properties. The first is that filenames are assumed to be unique. The second, a consequence of the first, is that files are versioned. To see what this means, let's create a GridFileSystem instance:
|
92
|
-
|
93
|
-
#### Saving files
|
94
|
-
|
95
|
-
@db = Mongo::Connection.new.db("social_site")
|
96
|
-
@fs = GridFileSystem.new(@db)
|
97
|
-
|
98
|
-
Now suppose we want to save the file 'me.jpg.' This is easily done using a filesystem-like API:
|
99
|
-
|
100
|
-
|
101
|
-
image = File.open("me.jpg")
|
102
|
-
@fs.open("me.jpg", "w") do |f|
|
103
|
-
f.write image
|
104
|
-
end
|
105
|
-
|
106
|
-
|
107
|
-
We can then retrieve the file by filename:
|
108
|
-
|
109
|
-
|
110
|
-
image = @fs.open("me.jpg", "r") {|f| f.read }
|
111
|
-
|
112
|
-
|
113
|
-
No problems there. But what if we need to replace the file? That too is straightforward:
|
114
|
-
|
115
|
-
|
116
|
-
image = File.open("me-dancing.jpg")
|
117
|
-
@fs.open("me.jpg", "w") do |f|
|
118
|
-
f.write image
|
119
|
-
end
|
120
|
-
|
121
|
-
|
122
|
-
But a couple things need to be kept in mind. First is that the original 'me.jpg' will be available until the new 'me.jpg' saves. From then on, calls to the #open method will always return the most recently saved version of a file. But, and this the second point, old versions of the file won't be deleted. So if you're going to be rewriting files often, you could end up with a lot of old versions piling up. One solution to this is to use the :delete_old options when writing a file:
|
123
|
-
|
124
|
-
|
125
|
-
image = File.open("me-dancing.jpg")
|
126
|
-
@fs.open("me.jpg", "w", :delete_old => true) do |f|
|
127
|
-
f.write image
|
128
|
-
end
|
129
|
-
|
130
|
-
|
131
|
-
This will delete all but the latest version of the file.
|
132
|
-
|
133
|
-
|
134
|
-
#### Deleting files
|
135
|
-
|
136
|
-
When you delete a file by name, you delete all versions of that file:
|
137
|
-
|
138
|
-
|
139
|
-
@fs.delete("me.jpg")
|
140
|
-
|
141
|
-
|
142
|
-
#### Metadata and safe mode
|
143
|
-
|
144
|
-
All of the options for storing metadata and saving in safe mode are available for the GridFileSystem class:
|
145
|
-
|
146
|
-
|
147
|
-
image = File.open("me.jpg")
|
148
|
-
@fs.open('my-avatar.jpg', w,
|
149
|
-
:content_type => "application/jpg",
|
150
|
-
:metadata => {'description' => "taken on 3/1/2010 after a game of ultimate"},
|
151
|
-
:_id => 'a-unique-id-to-use-instead-of-the-automatically-generated-one',
|
152
|
-
:safe => true) { |f| f.write image }
|
153
|
-
|
154
|
-
|
155
|
-
### Advanced Users
|
156
|
-
|
157
|
-
Astute code readers will notice that the Grid and GridFileSystem classes are merely thin wrappers around an underlying [GridIO class](http://api.mongodb.org/ruby/current/Mongo/GridIO.html). This means that it's easy to customize the GridFS implementation presented here; just use GridIO for all the low-level work, and build the API you need in an external manager class similar to Grid or GridFileSystem.
|
158
|
-
|
data/docs/HISTORY.md
DELETED
@@ -1,244 +0,0 @@
|
|
1
|
-
# MongoDB Ruby Driver History
|
2
|
-
|
3
|
-
### 1.3.0
|
4
|
-
2011-4-04
|
5
|
-
|
6
|
-
* Add option to set timeouts on socket read calls using the
|
7
|
-
Mongo::Connection :op_timeout option.
|
8
|
-
* Add StringIO methods to GridIO objects
|
9
|
-
* Support for BSON timestamp type with BSON::Timestamp
|
10
|
-
* Change the BSON binary subtype from 2 to 0
|
11
|
-
* Remove private method Connection#reset_conection
|
12
|
-
and deprecate public method ReplSetConnection#reset_connection
|
13
|
-
* ByteBuffer#== and OrderedHash#dup (Hongli Lai)
|
14
|
-
* Better check for UTF8 validity in Ruby 1.9
|
15
|
-
* Added previously removed Connection#host and Connection#port
|
16
|
-
* Added transformers to allow Mongo::Cursor to allow instantiated objects (John Nunemaker)
|
17
|
-
* Automated reconnection on fork
|
18
|
-
* Added Cursor#next alias for Cursor#next_document
|
19
|
-
* Audit tests after enabling warnings (Wojciech Piekutowski)
|
20
|
-
* Various bug fixes thanks to Datanoise, Hongli Lai, and Mauro Pompilio
|
21
|
-
|
22
|
-
### 1.2.4
|
23
|
-
2011-2-23
|
24
|
-
|
25
|
-
* Fix the exception message shown when there's an IOError (Mauro Pompilio)
|
26
|
-
* Another update to map-reduce docs for v1.8. Note that if you use the new
|
27
|
-
output option {:out => {:inline => true}}, then you must also specify
|
28
|
-
:raw => true.
|
29
|
-
|
30
|
-
### 1.2.3
|
31
|
-
2011-2-22
|
32
|
-
|
33
|
-
* Update docs for map-reduce command
|
34
|
-
* Minor doc fix
|
35
|
-
|
36
|
-
### 1.2.2
|
37
|
-
2011-2-15
|
38
|
-
|
39
|
-
* Improved replica set failover for edge case.
|
40
|
-
* Fix for REE on OSX (Hongli Lai)
|
41
|
-
|
42
|
-
### 1.2.1
|
43
|
-
2011-1-18
|
44
|
-
|
45
|
-
* Enable authentication with connection pooling.
|
46
|
-
* Allow custom logging with Connection#instrument (CodeMonkeySteve)
|
47
|
-
* Minor fixes and doc improvements.
|
48
|
-
|
49
|
-
### 1.2.0
|
50
|
-
2011-1-18
|
51
|
-
|
52
|
-
* Some minor improvements. See commit history.
|
53
|
-
|
54
|
-
### 1.2.rc0
|
55
|
-
2011-1-5
|
56
|
-
|
57
|
-
Lots of cleanup and minor bug fixes.
|
58
|
-
* Issues resolved: http://jira.mongodb.org/browse/RUBY/fixforversion/10222
|
59
|
-
* Updated Java BSON to Java driver 2.4.
|
60
|
-
* Platform gem for JRuby bson.
|
61
|
-
|
62
|
-
### 1.1.5
|
63
|
-
2010-12-15
|
64
|
-
|
65
|
-
* ReplSetConnection class. This must be used for replica set connections from
|
66
|
-
now on. You can still use Connection.multi, but that method has been deprecated.
|
67
|
-
* Automated replica set tests. rake test:rs
|
68
|
-
* Check that request and response ids match.
|
69
|
-
* Several bug fixes. See the commit history for details.
|
70
|
-
|
71
|
-
### 1.1.4
|
72
|
-
2010-11-30
|
73
|
-
|
74
|
-
* Important connection failure fix.
|
75
|
-
* ObjectId#to_s optimization (David Cuadrado).
|
76
|
-
|
77
|
-
### 1.1.3
|
78
|
-
2010-11-29
|
79
|
-
|
80
|
-
* Distributed reads for replica set secondaries. See /docs/examples/replica_set.rb and
|
81
|
-
http://api.mongodb.org/ruby/current/file.REPLICA_SETS.html for details.
|
82
|
-
* Note: when connecting to a replica set, you must use Connection#multi.
|
83
|
-
* Cursor#count takes optional skip and limit
|
84
|
-
* Collection#ensure_index for caching index creation calls
|
85
|
-
* Collection#update and Collection#remove now return error object when using safe mode
|
86
|
-
* Important fix for int/long serialization on bug introduced in 1.0.9
|
87
|
-
* Numerous tweaks and bug fixes.
|
88
|
-
|
89
|
-
### 1.1.2
|
90
|
-
2010-11-4
|
91
|
-
|
92
|
-
* Two critical fixes to automated failover and replica sets.
|
93
|
-
* Bug passing :timeout to Cursor.
|
94
|
-
* Permit safe mode specification on Connection, Collection, and DB levels.
|
95
|
-
* Specify replica set name on connect to verify connection to the right set.
|
96
|
-
* Misc. reorganization of project and docs.
|
97
|
-
|
98
|
-
### 1.1.1
|
99
|
-
2010-10-14
|
100
|
-
|
101
|
-
* Several critical JRuby bug fixes
|
102
|
-
* Fixes for JRuby in 1.9 mode
|
103
|
-
* Check keys and move id only when necessary for JRuby encoder
|
104
|
-
|
105
|
-
## 1.1
|
106
|
-
2010-10-4
|
107
|
-
|
108
|
-
* Official JRuby support via Java extensons for BSON (beta)
|
109
|
-
* Connection#lock! and Connection#unlock! for easy fsync lock
|
110
|
-
* Note: BSON::Code is no longer a subclass of String.
|
111
|
-
|
112
|
-
### 1.0.9
|
113
|
-
2010-9-20
|
114
|
-
|
115
|
-
* Significant performance improvements (with a lot of help from Hongli Lai)
|
116
|
-
|
117
|
-
### 1.0.8
|
118
|
-
2010-8-27
|
119
|
-
|
120
|
-
* Cursor#rewind! and more consistent Cursor Enumberable behavior
|
121
|
-
* Deprecated ObjectID for ObjectId
|
122
|
-
* Numerous minor bug fixes.
|
123
|
-
|
124
|
-
### 1.0.7
|
125
|
-
2010-8-4
|
126
|
-
|
127
|
-
* A few minor test/doc fixes.
|
128
|
-
* Better tests for replica sets and replication acknowledgment.
|
129
|
-
* Deprecated DB#error and DB#last_status
|
130
|
-
|
131
|
-
### 1.0.6
|
132
|
-
2010-7-26
|
133
|
-
|
134
|
-
* Replica set support.
|
135
|
-
* Collection#map_reduce bug fix.
|
136
|
-
|
137
|
-
### 1.0.5
|
138
|
-
2010-7-13
|
139
|
-
|
140
|
-
* Fix for bug introduced in 1.0.4.
|
141
|
-
|
142
|
-
### 1.0.4
|
143
|
-
2010-7-13
|
144
|
-
|
145
|
-
* Removed deprecated
|
146
|
-
* Cursor admin option
|
147
|
-
* DB#query
|
148
|
-
* DB#create_index (use Collection#create_index)
|
149
|
-
* DB#command only takes hash options now
|
150
|
-
* j2bson executable (neomantra)
|
151
|
-
* Fixed bson_ext compilation on Solaris (slyphon)
|
152
|
-
* System JS helpers (neovintage)
|
153
|
-
* Use one mutex per thread on pooled connections (cremes)
|
154
|
-
* Check for CursorNotFound response flag
|
155
|
-
* MapReduce can return raw command output using :raw
|
156
|
-
* BSON::OrderedHash equality with other Ruby hashes (Ryan Angilly)
|
157
|
-
* Fix for broken Socket.send with large payloads (Frédéric De Jaeger)
|
158
|
-
* Lots of minor improvements. See commmits.
|
159
|
-
|
160
|
-
### 1.0.3
|
161
|
-
2010-6-15
|
162
|
-
|
163
|
-
* Optimiztion for BSON::OrderedHash
|
164
|
-
* Some important fixes.
|
165
|
-
|
166
|
-
### 1.0.2
|
167
|
-
2010-6-5
|
168
|
-
|
169
|
-
This is a minor release for fixing an incompatibility with MongoDB v1.5.2
|
170
|
-
|
171
|
-
* Fix for boolean response on commands for core server v1.5.2
|
172
|
-
* BSON.read_bson_document and b2json executable (neomantra)
|
173
|
-
* BSON::ObjectID() shortcut for BSON::ObjectID.from_string (tmm1)
|
174
|
-
* Various bug fixes.
|
175
|
-
|
176
|
-
### 1.0.1
|
177
|
-
2010-5-7
|
178
|
-
|
179
|
-
* set Encoding.default_internal
|
180
|
-
* DEPRECATE JavaScript string on Collection#find. You now must specify $where explicitly.
|
181
|
-
* Added Grid#exist? and GridFileSystem#exist?
|
182
|
-
* Support for replication acknowledgment
|
183
|
-
* Support for $slice
|
184
|
-
* Namespaced OrderedHash under BSON (sleverbor)
|
185
|
-
|
186
|
-
## 1.0
|
187
|
-
2010-4-29
|
188
|
-
Note: if upgrading from versions prior to 0.20, be sure to upgrade
|
189
|
-
to 0.20 before upgrading to 1.0.
|
190
|
-
|
191
|
-
* Inspected ObjectID is represented in MongoDB extended json format.
|
192
|
-
* Support for tailable cursors.
|
193
|
-
* Configurable query response batch size (thx. to Aman Gupta)
|
194
|
-
|
195
|
-
* bson_ext installs on early release of Ruby 1.8.5 (dfitzgibbon)
|
196
|
-
* Deprecated DB#create_index. Use Collection#create_index index.
|
197
|
-
* Removed deprecated Grid#put syntax; no longer requires a filename.
|
198
|
-
|
199
|
-
### 0.20.1
|
200
|
-
2010-4-7
|
201
|
-
|
202
|
-
* Added bson gem dependency.
|
203
|
-
|
204
|
-
### 0.20
|
205
|
-
2010-4-7
|
206
|
-
|
207
|
-
If upgrading from a previous version of the Ruby driver, please read these notes carefully,
|
208
|
-
along with the 0.20_UPGRADE doc.
|
209
|
-
|
210
|
-
* Support for new commands:
|
211
|
-
* Collection#find_and_modify
|
212
|
-
* Collection#stats
|
213
|
-
* DB#stats
|
214
|
-
* Query :fields options allows for values of 0 to exclude fields (houdini, railsjedi).
|
215
|
-
* GridFS
|
216
|
-
* Option to delete old versions of GridFileSystem entries.
|
217
|
-
* Filename is now optional for Grid#put.
|
218
|
-
* Option to write arbitrary attributes to a file: @grid.put(@data, :favorite_phrase => "blimey!")
|
219
|
-
* Indexes created on the chunks collection are now unique. If you have an existing chunks collection,
|
220
|
-
you may want to remove
|
221
|
-
* Removed the following deprecated items:
|
222
|
-
* GridStore class
|
223
|
-
* RegexpOfHolding class
|
224
|
-
* Paired connections must now be initialized with Connection.paired
|
225
|
-
|
226
|
-
* BSON-related code extracted into two separate gems: bson and bson_ext (thx to Chuck Remes).
|
227
|
-
* mongo_ext no longer exists.
|
228
|
-
* BSON::Binary constructor can now take a string, which will be packed into an array.
|
229
|
-
* Exception class adjustments:
|
230
|
-
* Mongo::InvalidObjectID moved to BSON::InvalidObjectID
|
231
|
-
* Mongo::InvalidDocument moved to BSON::InvalidDocument
|
232
|
-
* Mongo::InvalidStringEncoding moved to BSON::InvalidStringEncoding
|
233
|
-
* Mongo::InvalidName replaced by Mongo::InvalidNSName and BSON::InvalidKeyName
|
234
|
-
* BSON types are now namespaced under the BSON module. These types include:
|
235
|
-
* Binary
|
236
|
-
* ObjectID
|
237
|
-
* Code
|
238
|
-
* DBRef
|
239
|
-
* MinKey and MaxKey
|
240
|
-
* Extensions compile on Rubinius (Chuck Remes).
|
241
|
-
|
242
|
-
## Prior to 0.20
|
243
|
-
|
244
|
-
See git revisions.
|
data/docs/RELEASES.md
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# MongoDB Ruby Driver Release Plan
|
2
|
-
|
3
|
-
This is a description of a formalized release plan that will take effect
|
4
|
-
with version 1.3.0.
|
5
|
-
|
6
|
-
## Semantic versioning
|
7
|
-
|
8
|
-
The most significant difference is that releases will now adhere to the conventions of
|
9
|
-
[semantic versioning](http://semver.org). In particular, we will strictly abide by the
|
10
|
-
following release rules:
|
11
|
-
|
12
|
-
1. Patch versions of the driver (Z in x.y.Z) will be released only when backward-compatible bug fixes are introduced. A bug fix is defined as an internal change that fixes incorrect behavior.
|
13
|
-
|
14
|
-
2. Minor versions (Y in x.Y.z) will be released if new, backward-compatible functionality is introduced to the public API.
|
15
|
-
|
16
|
-
3. Major versions (X in X.y.z) will be incremented if any backward-incompatibl changes are introduced to the public API.
|
17
|
-
|
18
|
-
This policy will clearly indicate to users when an upgrade may affect their code. As a side effect, version numbers will climb more quickly than before.
|
19
|
-
|
20
|
-
|
21
|
-
## Release checklist
|
22
|
-
|
23
|
-
Before each relese to Rubygems.org, the following steps will be taken:
|
24
|
-
|
25
|
-
1. All driver tests will be run on Linux, OS X, and Windows via continuous integration system.
|
26
|
-
|
27
|
-
2. HISTORY file will document all significant commits.
|
28
|
-
|
29
|
-
3. Version number will be incremented per the semantic version spec described above.
|
30
|
-
|
31
|
-
4. Appropriate branches and tags will be created in Git repository, as necessary.
|
32
|
-
|
33
|
-
5. Docs will be updated to the latest version of the driver and posted [online](http://api.mongodb.org/ruby/current/index.html).
|
data/docs/REPLICA_SETS.md
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
# Replica Sets in Ruby
|
2
|
-
|
3
|
-
Here follow a few considerations for those using the MongoDB Ruby driver with [replica sets](http://www.mongodb.org/display/DOCS/Replica+Sets).
|
4
|
-
|
5
|
-
### Setup
|
6
|
-
|
7
|
-
First, make sure that you've configured and initialized a replica set.
|
8
|
-
|
9
|
-
Use `ReplSetConnection.new` to connect to a replica set. This method, which accepts a variable number of arugments,
|
10
|
-
takes a list of seed nodes followed by any connection options. You'll want to specify at least two seed nodes. This gives
|
11
|
-
the driver more chances to connect in the event that any one seed node is offline. Once the driver connects, it will
|
12
|
-
cache the replica set topology as reported by the given seed node and use that information if a failover is later required.
|
13
|
-
|
14
|
-
@connection = ReplSetConnection.new(['n1.mydb.net', 27017], ['n2.mydb.net', 27017], ['n3.mydb.net', 27017])
|
15
|
-
|
16
|
-
### Read slaves
|
17
|
-
|
18
|
-
If you want to read from a seconday node, you can pass :read_secondary => true to ReplSetConnection#new.
|
19
|
-
|
20
|
-
@connection = ReplSetConnection.new(['n1.mydb.net', 27017], ['n2.mydb.net', 27017], ['n3.mydb.net', 27017],
|
21
|
-
:read_secondary => true)
|
22
|
-
|
23
|
-
A random secondary will be chosen to be read from. In a typical multi-process Ruby application, you'll have a good distribution of reads across secondary nodes.
|
24
|
-
|
25
|
-
### Connection Failures
|
26
|
-
|
27
|
-
Imagine that either the master node or one of the read nodes goes offline. How will the driver respond?
|
28
|
-
|
29
|
-
If any read operation fails, the driver will raise a *ConnectionFailure* exception. It then becomes the client's responsibility to decide how to handle this.
|
30
|
-
|
31
|
-
If the client decides to retry, it's not guaranteed that another member of the replica set will have been promoted to master right away, so it's still possible that the driver will raise another *ConnectionFailure*. However, once a member has been promoted to master, typically within a few seconds, subsequent operations will succeed.
|
32
|
-
|
33
|
-
The driver will essentially cycle through all known seed addresses until a node identifies itself as master.
|
34
|
-
|
35
|
-
### Recovery
|
36
|
-
|
37
|
-
Driver users may wish to wrap their database calls with failure recovery code. Here's one possibility, which will attempt to connection
|
38
|
-
every half second and time out after thirty seconds.
|
39
|
-
|
40
|
-
# Ensure retry upon failure
|
41
|
-
def rescue_connection_failure(max_retries=60)
|
42
|
-
retries = 0
|
43
|
-
begin
|
44
|
-
yield
|
45
|
-
rescue Mongo::ConnectionFailure => ex
|
46
|
-
retries += 1
|
47
|
-
raise ex if retries > max_retries
|
48
|
-
sleep(0.5)
|
49
|
-
retry
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# Wrapping a call to #count()
|
54
|
-
rescue_connection_failure do
|
55
|
-
@db.collection('users').count()
|
56
|
-
end
|
57
|
-
|
58
|
-
Of course, the proper way to handle connection failures will always depend on the individual application. We encourage object-mapper and application developers to publish any promising results.
|
59
|
-
|
60
|
-
### Testing
|
61
|
-
|
62
|
-
The Ruby driver (>= 1.1.5) includes unit tests for verifying replica set behavior. They reside in *tests/replica_sets*. You can run them as a group with the following rake task:
|
63
|
-
|
64
|
-
rake test:rs
|
65
|
-
|
66
|
-
The suite will set up a five-node replica set by itself and ensure that driver behaves correctly even in the face
|
67
|
-
of individual node failures. Note that the `mongod` executable must be in the search path for this to work.
|
68
|
-
|
69
|
-
### Further Reading
|
70
|
-
|
71
|
-
* [Replica Sets](http://www.mongodb.org/display/DOCS/Replica+Set+Configuration)
|
72
|
-
* [Replics Set Configuration](http://www.mongodb.org/display/DOCS/Replica+Set+Configuration)
|