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.
Files changed (185) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/{LICENSE.txt → LICENSE} +1 -1
  4. data/README.md +122 -271
  5. data/Rakefile +25 -209
  6. data/VERSION +1 -0
  7. data/bin/mongo_console +31 -9
  8. data/lib/mongo/bulk_write_collection_view.rb +387 -0
  9. data/lib/mongo/collection.rb +576 -269
  10. data/lib/mongo/collection_writer.rb +364 -0
  11. data/lib/mongo/connection/node.rb +249 -0
  12. data/lib/mongo/connection/pool.rb +340 -0
  13. data/lib/mongo/connection/pool_manager.rb +320 -0
  14. data/lib/mongo/connection/sharding_pool_manager.rb +67 -0
  15. data/lib/mongo/connection/socket/socket_util.rb +37 -0
  16. data/lib/mongo/connection/socket/ssl_socket.rb +95 -0
  17. data/lib/mongo/connection/socket/tcp_socket.rb +87 -0
  18. data/lib/mongo/connection/socket/unix_socket.rb +39 -0
  19. data/lib/mongo/connection/socket.rb +18 -0
  20. data/lib/mongo/connection.rb +7 -875
  21. data/lib/mongo/cursor.rb +403 -117
  22. data/lib/mongo/db.rb +444 -243
  23. data/lib/mongo/exception.rb +145 -0
  24. data/lib/mongo/functional/authentication.rb +455 -0
  25. data/lib/mongo/functional/logging.rb +85 -0
  26. data/lib/mongo/functional/read_preference.rb +183 -0
  27. data/lib/mongo/functional/scram.rb +556 -0
  28. data/lib/mongo/functional/uri_parser.rb +409 -0
  29. data/lib/mongo/functional/write_concern.rb +66 -0
  30. data/lib/mongo/functional.rb +20 -0
  31. data/lib/mongo/gridfs/grid.rb +30 -24
  32. data/lib/mongo/gridfs/grid_ext.rb +6 -10
  33. data/lib/mongo/gridfs/grid_file_system.rb +38 -20
  34. data/lib/mongo/gridfs/grid_io.rb +84 -75
  35. data/lib/mongo/gridfs.rb +18 -0
  36. data/lib/mongo/legacy.rb +140 -0
  37. data/lib/mongo/mongo_client.rb +697 -0
  38. data/lib/mongo/mongo_replica_set_client.rb +535 -0
  39. data/lib/mongo/mongo_sharded_client.rb +159 -0
  40. data/lib/mongo/networking.rb +372 -0
  41. data/lib/mongo/{util → utils}/conversions.rb +29 -8
  42. data/lib/mongo/{util → utils}/core_ext.rb +28 -18
  43. data/lib/mongo/{util → utils}/server_version.rb +4 -6
  44. data/lib/mongo/{util → utils}/support.rb +29 -31
  45. data/lib/mongo/utils/thread_local_variable_manager.rb +25 -0
  46. data/lib/mongo/utils.rb +19 -0
  47. data/lib/mongo.rb +51 -50
  48. data/mongo.gemspec +29 -32
  49. data/test/functional/authentication_test.rb +39 -0
  50. data/test/functional/bulk_api_stress_test.rb +133 -0
  51. data/test/functional/bulk_write_collection_view_test.rb +1198 -0
  52. data/test/functional/client_test.rb +627 -0
  53. data/test/functional/collection_test.rb +2175 -0
  54. data/test/functional/collection_writer_test.rb +83 -0
  55. data/test/{conversions_test.rb → functional/conversions_test.rb} +47 -3
  56. data/test/functional/cursor_fail_test.rb +57 -0
  57. data/test/functional/cursor_message_test.rb +56 -0
  58. data/test/functional/cursor_test.rb +683 -0
  59. data/test/functional/db_api_test.rb +835 -0
  60. data/test/functional/db_connection_test.rb +25 -0
  61. data/test/functional/db_test.rb +348 -0
  62. data/test/functional/grid_file_system_test.rb +285 -0
  63. data/test/{grid_io_test.rb → functional/grid_io_test.rb} +72 -11
  64. data/test/{grid_test.rb → functional/grid_test.rb} +88 -15
  65. data/test/functional/pool_test.rb +136 -0
  66. data/test/functional/safe_test.rb +98 -0
  67. data/test/functional/ssl_test.rb +29 -0
  68. data/test/functional/support_test.rb +62 -0
  69. data/test/functional/timeout_test.rb +60 -0
  70. data/test/functional/uri_test.rb +446 -0
  71. data/test/functional/write_concern_test.rb +118 -0
  72. data/test/helpers/general.rb +50 -0
  73. data/test/helpers/test_unit.rb +476 -0
  74. data/test/replica_set/authentication_test.rb +37 -0
  75. data/test/replica_set/basic_test.rb +189 -0
  76. data/test/replica_set/client_test.rb +393 -0
  77. data/test/replica_set/connection_test.rb +138 -0
  78. data/test/replica_set/count_test.rb +66 -0
  79. data/test/replica_set/cursor_test.rb +220 -0
  80. data/test/replica_set/insert_test.rb +157 -0
  81. data/test/replica_set/max_values_test.rb +151 -0
  82. data/test/replica_set/pinning_test.rb +105 -0
  83. data/test/replica_set/query_test.rb +73 -0
  84. data/test/replica_set/read_preference_test.rb +219 -0
  85. data/test/replica_set/refresh_test.rb +211 -0
  86. data/test/replica_set/replication_ack_test.rb +95 -0
  87. data/test/replica_set/ssl_test.rb +32 -0
  88. data/test/sharded_cluster/basic_test.rb +203 -0
  89. data/test/shared/authentication/basic_auth_shared.rb +260 -0
  90. data/test/shared/authentication/bulk_api_auth_shared.rb +249 -0
  91. data/test/shared/authentication/gssapi_shared.rb +176 -0
  92. data/test/shared/authentication/sasl_plain_shared.rb +96 -0
  93. data/test/shared/authentication/scram_shared.rb +92 -0
  94. data/test/shared/ssl_shared.rb +235 -0
  95. data/test/test_helper.rb +53 -94
  96. data/test/threading/basic_test.rb +120 -0
  97. data/test/tools/mongo_config.rb +708 -0
  98. data/test/tools/mongo_config_test.rb +160 -0
  99. data/test/unit/client_test.rb +381 -0
  100. data/test/unit/collection_test.rb +89 -53
  101. data/test/unit/connection_test.rb +282 -32
  102. data/test/unit/cursor_test.rb +206 -8
  103. data/test/unit/db_test.rb +55 -13
  104. data/test/unit/grid_test.rb +43 -16
  105. data/test/unit/mongo_sharded_client_test.rb +48 -0
  106. data/test/unit/node_test.rb +93 -0
  107. data/test/unit/pool_manager_test.rb +111 -0
  108. data/test/unit/read_pref_test.rb +406 -0
  109. data/test/unit/read_test.rb +159 -0
  110. data/test/unit/safe_test.rb +69 -36
  111. data/test/unit/sharding_pool_manager_test.rb +84 -0
  112. data/test/unit/write_concern_test.rb +175 -0
  113. data.tar.gz.sig +3 -0
  114. metadata +227 -216
  115. metadata.gz.sig +0 -0
  116. data/docs/CREDITS.md +0 -123
  117. data/docs/FAQ.md +0 -116
  118. data/docs/GridFS.md +0 -158
  119. data/docs/HISTORY.md +0 -244
  120. data/docs/RELEASES.md +0 -33
  121. data/docs/REPLICA_SETS.md +0 -72
  122. data/docs/TUTORIAL.md +0 -247
  123. data/docs/WRITE_CONCERN.md +0 -28
  124. data/lib/mongo/exceptions.rb +0 -71
  125. data/lib/mongo/gridfs/grid_io_fix.rb +0 -38
  126. data/lib/mongo/repl_set_connection.rb +0 -342
  127. data/lib/mongo/test.rb +0 -20
  128. data/lib/mongo/util/pool.rb +0 -177
  129. data/lib/mongo/util/uri_parser.rb +0 -185
  130. data/test/async/collection_test.rb +0 -224
  131. data/test/async/connection_test.rb +0 -24
  132. data/test/async/cursor_test.rb +0 -162
  133. data/test/async/worker_pool_test.rb +0 -99
  134. data/test/auxillary/1.4_features.rb +0 -166
  135. data/test/auxillary/authentication_test.rb +0 -68
  136. data/test/auxillary/autoreconnect_test.rb +0 -41
  137. data/test/auxillary/fork_test.rb +0 -30
  138. data/test/auxillary/repl_set_auth_test.rb +0 -58
  139. data/test/auxillary/slave_connection_test.rb +0 -36
  140. data/test/auxillary/threaded_authentication_test.rb +0 -101
  141. data/test/bson/binary_test.rb +0 -15
  142. data/test/bson/bson_test.rb +0 -649
  143. data/test/bson/byte_buffer_test.rb +0 -208
  144. data/test/bson/hash_with_indifferent_access_test.rb +0 -38
  145. data/test/bson/json_test.rb +0 -17
  146. data/test/bson/object_id_test.rb +0 -154
  147. data/test/bson/ordered_hash_test.rb +0 -204
  148. data/test/bson/timestamp_test.rb +0 -24
  149. data/test/collection_test.rb +0 -910
  150. data/test/connection_test.rb +0 -309
  151. data/test/cursor_fail_test.rb +0 -75
  152. data/test/cursor_message_test.rb +0 -43
  153. data/test/cursor_test.rb +0 -483
  154. data/test/db_api_test.rb +0 -726
  155. data/test/db_connection_test.rb +0 -15
  156. data/test/db_test.rb +0 -287
  157. data/test/grid_file_system_test.rb +0 -243
  158. data/test/load/resque/load.rb +0 -21
  159. data/test/load/resque/processor.rb +0 -26
  160. data/test/load/thin/load.rb +0 -24
  161. data/test/load/unicorn/load.rb +0 -23
  162. data/test/load/unicorn/unicorn.rb +0 -29
  163. data/test/replica_sets/connect_test.rb +0 -94
  164. data/test/replica_sets/connection_string_test.rb +0 -32
  165. data/test/replica_sets/count_test.rb +0 -35
  166. data/test/replica_sets/insert_test.rb +0 -53
  167. data/test/replica_sets/pooled_insert_test.rb +0 -55
  168. data/test/replica_sets/query_secondaries.rb +0 -96
  169. data/test/replica_sets/query_test.rb +0 -51
  170. data/test/replica_sets/replication_ack_test.rb +0 -66
  171. data/test/replica_sets/rs_test_helper.rb +0 -27
  172. data/test/safe_test.rb +0 -68
  173. data/test/support/hash_with_indifferent_access.rb +0 -186
  174. data/test/support/keys.rb +0 -45
  175. data/test/support_test.rb +0 -18
  176. data/test/threading/threading_with_large_pool_test.rb +0 -90
  177. data/test/threading_test.rb +0 -87
  178. data/test/tools/auth_repl_set_manager.rb +0 -14
  179. data/test/tools/load.rb +0 -58
  180. data/test/tools/repl_set_manager.rb +0 -266
  181. data/test/tools/sharding_manager.rb +0 -202
  182. data/test/tools/test.rb +0 -4
  183. data/test/unit/pool_test.rb +0 -9
  184. data/test/unit/repl_set_connection_test.rb +0 -59
  185. data/test/uri_test.rb +0 -91
data/docs/TUTORIAL.md DELETED
@@ -1,247 +0,0 @@
1
- # MongoDB Ruby Driver Tutorial
2
-
3
- This tutorial gives many common examples of using MongoDB with the Ruby driver. If you're looking for information on data modeling, see [MongoDB Data Modeling and Rails](http://www.mongodb.org/display/DOCS/MongoDB+Data+Modeling+and+Rails). Links to the various object mappers are listed on our [object mappers page](http://www.mongodb.org/display/DOCS/Object+Mappers+for+Ruby+and+MongoDB).
4
-
5
- Interested in GridFS? See [GridFS in Ruby](file.GridFS.html).
6
-
7
- As always, the [latest source for the Ruby driver](http://github.com/mongodb/mongo-ruby-driver) can be found on [github](http://github.com/mongodb/mongo-ruby-driver/).
8
-
9
- ## Installation
10
-
11
- The mongo-ruby-driver gem is served through Rubygems.org. To install, make sure you have the latest version of rubygems.
12
- gem update --system
13
- Next, install the mongo rubygem:
14
- gem install mongo
15
-
16
- The required `bson` gem will be installed automatically.
17
-
18
- For optimum performance, install the bson_ext gem:
19
-
20
- gem install bson_ext
21
-
22
- After installing, you may want to look at the [examples](http://github.com/mongodb/mongo-ruby-driver/tree/master/examples) directory included in the source distribution. These examples walk through some of the basics of using the Ruby driver.
23
-
24
- ## Getting started
25
-
26
- #### Using the gem
27
-
28
- All of the code here assumes that you have already executed the following Ruby code:
29
-
30
- require 'rubygems' # not necessary for Ruby 1.9
31
- require 'mongo'
32
-
33
- #### Making a Connection
34
-
35
- An `Mongo::Connection` instance represents a connection to MongoDB. You use a Connection instance to obtain an Mongo:DB instance, which represents a named database. The database doesn't have to exist - if it doesn't, MongoDB will create it for you.
36
-
37
- You can optionally specify the MongoDB server address and port when connecting. The following example shows three ways to connect to the database "mydb" on the local machine:
38
-
39
- db = Mongo::Connection.new.db("mydb")
40
- db = Mongo::Connection.new("localhost").db("mydb")
41
- db = Mongo::Connection.new("localhost", 27017).db("mydb")
42
-
43
- At this point, the `db` object will be a connection to a MongoDB server for the specified database. Each DB instance uses a separate socket connection to the server.
44
-
45
- If you're trying to connect to a replica set, see [Replica Sets in Ruby](http://www.mongodb.org/display/DOCS/Replica+Sets+in+Ruby).
46
-
47
- #### Listing All Databases
48
-
49
- connection = Mongo::Connection.new # (optional host/port args)
50
- connection.database_names.each { |name| puts name }
51
- connection.database_info.each { |info| puts info.inspect}
52
-
53
- #### Dropping a Database
54
- connection.drop_database('database_name')
55
-
56
- MongoDB can be run in a secure mode where access to databases is controlled through name and password authentication. When run in this mode, any client application must provide a name and password before doing any operations. In the Ruby driver, you simply do the following with the connected mongo object:
57
-
58
- auth = db.authenticate(my_user_name, my_password)
59
-
60
- If the name and password are valid for the database, `auth` will be `true`. Otherwise, it will be `false`. You should look at the MongoDB log for further information if available.
61
-
62
- #### Getting a List Of Collections
63
-
64
- Each database has zero or more collections. You can retrieve a list of them from the db (and print out any that are there):
65
-
66
- db.collection_names.each { |name| puts name }
67
-
68
- and assuming that there are two collections, name and address, in the database, you would see
69
-
70
- name
71
- address
72
-
73
- as the output.
74
-
75
- #### Getting a Collection
76
-
77
- You can get a collection to use using the `collection` method:
78
- coll = db.collection("testCollection")
79
- This is aliased to the \[\] method:
80
- coll = db["testCollection"]
81
-
82
- Once you have this collection object, you can now do things like insert data, query for data, etc.
83
-
84
- #### Inserting a Document
85
-
86
- Once you have the collection object, you can insert documents into the collection. For example, lets make a little document that in JSON would be represented as
87
-
88
- {
89
- "name" : "MongoDB",
90
- "type" : "database",
91
- "count" : 1,
92
- "info" : {
93
- x : 203,
94
- y : 102
95
- }
96
- }
97
-
98
- Notice that the above has an "inner" document embedded within it. To do this, we can use a Hash or the driver's OrderedHash (which preserves key order) to create the document (including the inner document), and then just simply insert it into the collection using the `insert()` method.
99
-
100
- doc = {"name" => "MongoDB", "type" => "database", "count" => 1,
101
- "info" => {"x" => 203, "y" => '102'`
102
- coll.insert(doc)
103
-
104
- #### Updating a Document
105
-
106
- We can update the previous document using the `update` method. There are a couple ways to update a document. We can rewrite it:
107
-
108
- doc["name"] = "MongoDB Ruby"
109
- coll.update({"_id" => doc["_id"]}, doc)
110
-
111
- Or we can use an atomic operator to change a single value:
112
-
113
- coll.update({"_id" => doc["_id"]}, {"$set" => {"name" => "MongoDB Ruby"`)
114
-
115
- Read [more about updating documents|Updating].
116
-
117
- #### Finding the First Document In a Collection using `find_one()`
118
-
119
- To show that the document we inserted in the previous step is there, we can do a simple `find_one()` operation to get the first document in the collection. This method returns a single document (rather than the `Cursor` that the `find()` operation returns).
120
-
121
- my_doc = coll.find_one()
122
- puts my_doc.inspect
123
-
124
- and you should see:
125
-
126
- {"_id"=>#<BSON::ObjectID:0x118576c ...>, "name"=>"MongoDB",
127
- "info"=>{"x"=>203, "y"=>102}, "type"=>"database", "count"=>1}
128
-
129
- Note the `\_id` element has been added automatically by MongoDB to your document.
130
-
131
- #### Adding Multiple Documents
132
-
133
- To demonstrate some more interesting queries, let's add multiple simple documents to the collection. These documents will have the following form:
134
- {
135
- "i" : value
136
- }
137
-
138
- Here's how to insert them:
139
-
140
- 100.times { |i| coll.insert("i" => i) }
141
-
142
- Notice that we can insert documents of different "shapes" into the same collection. These records are in the same collection as the complex record we inserted above. This aspect is what we mean when we say that MongoDB is "schema-free".
143
-
144
- #### Counting Documents in a Collection
145
-
146
- Now that we've inserted 101 documents (the 100 we did in the loop, plus the first one), we can check to see if we have them all using the `count()` method.
147
-
148
- puts coll.count()
149
-
150
- and it should print `101`.
151
-
152
- #### Using a Cursor to get all of the Documents
153
-
154
- To get all the documents from the collection, we use the `find()` method. `find()` returns a `Cursor` object, which allows us to iterate over the set of documents that matches our query. The Ruby driver's Cursor implemented Enumerable, which allows us to use `Enumerable#each`, `Enumerable#map}, etc. For instance:
155
-
156
- coll.find().each { |row| puts row.inspect }
157
-
158
- and that should print all 101 documents in the collection.
159
-
160
- #### Getting a Single Document with a Query
161
-
162
- We can create a _query_ hash to pass to the `find()` method to get a subset of the documents in our collection. For example, if we wanted to find the document for which the value of the "i" field is 71, we would do the following ;
163
-
164
- coll.find("i" => 71).each { |row| puts row.inspect }
165
-
166
- and it should just print just one document:
167
-
168
- {"_id"=>#<BSON::ObjectID:0x117de90 ...>, "i"=>71}
169
-
170
- #### Getting a Set of Documents With a Query
171
-
172
- We can use the query to get a set of documents from our collection. For example, if we wanted to get all documents where "i" > 50, we could write:
173
-
174
- coll.find("i" => {"$gt" => 50}).each { |row| puts row }
175
-
176
- which should print the documents where i > 50. We could also get a range, say 20 < i <= 30:
177
-
178
- coll.find("i" => {"$gt" => 20, "$lte" => 30}).each { |row| puts row }
179
-
180
- #### Selecting a subset of fields for a query
181
-
182
- Use the `:fields` option. If you just want fields "a" and "b":
183
-
184
- coll.find("i" => {"$gt" => 50}, :fields => ["a", "b"]).each { |row| puts row }
185
-
186
- #### Querying with Regular Expressions
187
-
188
- Regular expressions can be used to query MongoDB. To find all names that begin with 'a':
189
-
190
- coll.find({"name" => /^a/})
191
-
192
- You can also construct a regular expression dynamically. To match a given search string:
193
-
194
- search_string = params['search']
195
-
196
- # Constructor syntax
197
- coll.find({"name" => Regexp.new(search_string)})
198
-
199
- # Literal syntax
200
- coll.find({"name" => /#{search_string}/})
201
-
202
- Although MongoDB isn't vulnerable to anything like SQL-injection, it may be worth checking the search string for anything malicious.
203
-
204
- ## Indexing
205
-
206
- #### Creating An Index
207
-
208
- MongoDB supports indexes, and they are very easy to add on a collection. To create an index, you specify an index name and an array of field names to be indexed, or a single field name. The following creates an ascending index on the "i" field:
209
-
210
- # create_index assumes ascending order; see method docs
211
- # for details
212
- coll.create_index("i")
213
- To specify complex indexes or a descending index you need to use a slightly more complex syntax - the index specifier must be an Array of [field name, direction] pairs. Directions should be specified as Mongo::ASCENDING or Mongo::DESCENDING:
214
-
215
- # Explicit "ascending"
216
- coll.create_index([["i", Mongo::ASCENDING]])
217
-
218
- #### Creating and querying on a geospatial index
219
-
220
- First, create the index on a field containing long-lat values:
221
-
222
- people.create_index([["loc", Mongo::GEO2D]])
223
-
224
- Then get a list of the twenty locations nearest to the point 50, 50:
225
-
226
- people.find({"loc" => {"$near" => [50, 50]}}, {:limit => 20}).each do |p|
227
- puts p.inspect
228
- end
229
-
230
- #### Getting a List of Indexes on a Collection
231
-
232
- You can get a list of the indexes on a collection using `coll.index_information()`.
233
-
234
- ## Database Administration
235
-
236
- A database can have one of three profiling levels: off (:off), slow queries only (:slow_only), or all (:all). To see the database level:
237
-
238
- puts db.profiling_level # => off (the symbol :off printed as a string)
239
- db.profiling_level = :slow_only
240
-
241
- Validating a collection will return an interesting hash if all is well or raise an exception if there is a problem.
242
- p db.validate_collection('coll_name')
243
-
244
- ## See Also
245
-
246
- * [MongoDB Koans](http://github.com/chicagoruby/MongoDB_Koans) A path to MongoDB enlightenment via the Ruby driver.
247
- * [MongoDB Manual](http://www.mongodb.org/display/DOCS/Developer+Zone)
@@ -1,28 +0,0 @@
1
- # Write Concern in Ruby
2
-
3
- ## Setting the write concern
4
-
5
- Write concern is set using the `:safe` option. There are several possible options:
6
-
7
- @collection.save({:doc => 'foo'}, :safe => true)
8
- @collection.save({:doc => 'foo'}, :safe => {:w => 2})
9
- @collection.save({:doc => 'foo'}, :safe => {:w => 2, :wtimeout => 200})
10
- @collection.save({:doc => 'foo'}, :safe => {:w => 2, :wtimeout => 200, :fsync => true})
11
-
12
- The first, `true`, simply indicates that we should request a response from the server to ensure that to errors have occurred. The second, `{:w => 2}`forces the server to wait until at least two servers have recorded the write. The third does the same but will time out if the replication can't be completed in 200 milliseconds. The fourth forces an fsync on each server being written to (note: this option is rarely necessary and will have a dramaticly negative effect on performance).
13
-
14
- ## Write concern inheritance
15
-
16
- The Ruby driver allows you to set write concern on each of four levels: the connection, database, collection, and write operation.
17
- Objects will inherit the default write concern from their parents. Thus, if you set a write concern of `{:w => 1}` when creating
18
- a new connection, then all databases and collections created from that connection will inherit the same setting. See this code example:
19
-
20
- @con = Mongo::Connection.new('localhost', 27017, :safe => {:w => 2})
21
- @db = @con['test']
22
- @collection = @db['foo']
23
- @collection.save({:name => 'foo'})
24
-
25
- @collection.save({:name => 'bar'}, :safe => false)
26
-
27
- Here, the first call to Collection#save will use the inherited write concern, `{:w => 2}`. But notice that the second call
28
- to Collection#save overrides this setting.
@@ -1,71 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- #
4
- # --
5
- # Copyright (C) 2008-2011 10gen Inc.
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- # ++
19
-
20
- module Mongo
21
- # Generic Mongo Ruby Driver exception class.
22
- class MongoRubyError < StandardError; end
23
-
24
- # Raised when MongoDB itself has returned an error.
25
- class MongoDBError < RuntimeError; end
26
-
27
- # Raised when configuration options cause connections, queries, etc., to fail.
28
- class ConfigurationError < MongoRubyError; end
29
-
30
- # Raised on fatal errors to GridFS.
31
- class GridError < MongoRubyError; end
32
-
33
- # Raised on fatal errors to GridFS.
34
- class GridFileNotFound < GridError; end
35
-
36
- # Raised on fatal errors to GridFS.
37
- class GridMD5Failure < GridError; end
38
-
39
- # Raised when invalid arguments are sent to Mongo Ruby methods.
40
- class MongoArgumentError < MongoRubyError; end
41
-
42
- # Raised on failures in connection to the database server.
43
- class ConnectionError < MongoRubyError; end
44
-
45
- # Raised on failures in connection to the database server.
46
- class ReplicaSetConnectionError < ConnectionError; end
47
-
48
- # Raised on failures in connection to the database server.
49
- class ConnectionTimeoutError < MongoRubyError; end
50
-
51
- # Raised when a connection operation fails.
52
- class ConnectionFailure < MongoDBError; end
53
-
54
- # Raised when authentication fails.
55
- class AuthenticationError < MongoDBError; end
56
-
57
- # Raised when a database operation fails.
58
- class OperationFailure < MongoDBError; end
59
-
60
- # Raised when a socket read operation times out.
61
- class OperationTimeout < ::Timeout::Error; end
62
-
63
- # Raised when a client attempts to perform an invalid operation.
64
- class InvalidOperation < MongoDBError; end
65
-
66
- # Raised when an invalid collection or database name is used (invalid namespace name).
67
- class InvalidNSName < RuntimeError; end
68
-
69
- # Raised when the client supplies an invalid value to sort by.
70
- class InvalidSortValueError < MongoRubyError; end
71
- end
@@ -1,38 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- # --
4
- # Copyright (C) 2008-2011 10gen Inc.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- # ++
18
-
19
- module Mongo
20
- class GridIO
21
-
22
- # This fixes a comparson issue in JRuby 1.9
23
- def get_md5
24
- md5_command = BSON::OrderedHash.new
25
- md5_command['filemd5'] = @files_id
26
- md5_command['root'] = @fs_name
27
- @server_md5 = @files.db.command(md5_command)['md5']
28
- if @safe
29
- @client_md5 = @local_md5.hexdigest
30
- if @local_md5.to_s != @server_md5.to_s
31
- raise GridMD5Failure, "File on server failed MD5 check"
32
- end
33
- else
34
- @server_md5
35
- end
36
- end
37
- end
38
- end