mongo-lyon 1.2.4

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 (87) hide show
  1. data/LICENSE.txt +190 -0
  2. data/README.md +344 -0
  3. data/Rakefile +202 -0
  4. data/bin/mongo_console +34 -0
  5. data/docs/1.0_UPGRADE.md +21 -0
  6. data/docs/CREDITS.md +123 -0
  7. data/docs/FAQ.md +116 -0
  8. data/docs/GridFS.md +158 -0
  9. data/docs/HISTORY.md +225 -0
  10. data/docs/REPLICA_SETS.md +72 -0
  11. data/docs/TUTORIAL.md +247 -0
  12. data/docs/WRITE_CONCERN.md +28 -0
  13. data/lib/mongo.rb +77 -0
  14. data/lib/mongo/collection.rb +872 -0
  15. data/lib/mongo/connection.rb +875 -0
  16. data/lib/mongo/cursor.rb +449 -0
  17. data/lib/mongo/db.rb +607 -0
  18. data/lib/mongo/exceptions.rb +68 -0
  19. data/lib/mongo/gridfs/grid.rb +106 -0
  20. data/lib/mongo/gridfs/grid_ext.rb +57 -0
  21. data/lib/mongo/gridfs/grid_file_system.rb +145 -0
  22. data/lib/mongo/gridfs/grid_io.rb +394 -0
  23. data/lib/mongo/gridfs/grid_io_fix.rb +38 -0
  24. data/lib/mongo/repl_set_connection.rb +342 -0
  25. data/lib/mongo/util/conversions.rb +89 -0
  26. data/lib/mongo/util/core_ext.rb +60 -0
  27. data/lib/mongo/util/pool.rb +185 -0
  28. data/lib/mongo/util/server_version.rb +71 -0
  29. data/lib/mongo/util/support.rb +82 -0
  30. data/lib/mongo/util/uri_parser.rb +181 -0
  31. data/lib/mongo/version.rb +3 -0
  32. data/mongo.gemspec +34 -0
  33. data/test/auxillary/1.4_features.rb +166 -0
  34. data/test/auxillary/authentication_test.rb +68 -0
  35. data/test/auxillary/autoreconnect_test.rb +41 -0
  36. data/test/auxillary/repl_set_auth_test.rb +58 -0
  37. data/test/auxillary/slave_connection_test.rb +36 -0
  38. data/test/auxillary/threaded_authentication_test.rb +101 -0
  39. data/test/bson/binary_test.rb +15 -0
  40. data/test/bson/bson_test.rb +614 -0
  41. data/test/bson/byte_buffer_test.rb +190 -0
  42. data/test/bson/hash_with_indifferent_access_test.rb +38 -0
  43. data/test/bson/json_test.rb +17 -0
  44. data/test/bson/object_id_test.rb +154 -0
  45. data/test/bson/ordered_hash_test.rb +197 -0
  46. data/test/collection_test.rb +893 -0
  47. data/test/connection_test.rb +303 -0
  48. data/test/conversions_test.rb +120 -0
  49. data/test/cursor_fail_test.rb +75 -0
  50. data/test/cursor_message_test.rb +43 -0
  51. data/test/cursor_test.rb +457 -0
  52. data/test/db_api_test.rb +715 -0
  53. data/test/db_connection_test.rb +15 -0
  54. data/test/db_test.rb +287 -0
  55. data/test/grid_file_system_test.rb +244 -0
  56. data/test/grid_io_test.rb +120 -0
  57. data/test/grid_test.rb +200 -0
  58. data/test/load/thin/load.rb +24 -0
  59. data/test/load/unicorn/load.rb +23 -0
  60. data/test/replica_sets/connect_test.rb +86 -0
  61. data/test/replica_sets/connection_string_test.rb +32 -0
  62. data/test/replica_sets/count_test.rb +35 -0
  63. data/test/replica_sets/insert_test.rb +53 -0
  64. data/test/replica_sets/pooled_insert_test.rb +55 -0
  65. data/test/replica_sets/query_secondaries.rb +96 -0
  66. data/test/replica_sets/query_test.rb +51 -0
  67. data/test/replica_sets/replication_ack_test.rb +66 -0
  68. data/test/replica_sets/rs_test_helper.rb +27 -0
  69. data/test/safe_test.rb +68 -0
  70. data/test/support/hash_with_indifferent_access.rb +199 -0
  71. data/test/support/keys.rb +45 -0
  72. data/test/support_test.rb +19 -0
  73. data/test/test_helper.rb +83 -0
  74. data/test/threading/threading_with_large_pool_test.rb +90 -0
  75. data/test/threading_test.rb +87 -0
  76. data/test/tools/auth_repl_set_manager.rb +14 -0
  77. data/test/tools/repl_set_manager.rb +266 -0
  78. data/test/unit/collection_test.rb +130 -0
  79. data/test/unit/connection_test.rb +98 -0
  80. data/test/unit/cursor_test.rb +99 -0
  81. data/test/unit/db_test.rb +96 -0
  82. data/test/unit/grid_test.rb +49 -0
  83. data/test/unit/pool_test.rb +9 -0
  84. data/test/unit/repl_set_connection_test.rb +72 -0
  85. data/test/unit/safe_test.rb +125 -0
  86. data/test/uri_test.rb +91 -0
  87. metadata +202 -0
data/LICENSE.txt ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2008-2010 10gen, Inc.
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,344 @@
1
+ # Introduction
2
+
3
+ This is the 10gen-supported Ruby driver for [MongoDB](http://www.mongodb.org).
4
+
5
+ This documentation includes other articles of interest, include:
6
+
7
+ 1. [A tutorial](http://api.mongodb.org/ruby/current/file.TUTORIAL.html).
8
+ 2. [Replica Sets in Ruby](http://api.mongodb.org/ruby/current/file.REPLICA_SETS.html).
9
+ 3. [Write Concern in Ruby](http://api.mongodb.org/ruby/current/file.WRITE_CONCERN.html).
10
+ 4. [GridFS in Ruby](http://api.mongodb.org/ruby/current/file.GridFS.html).
11
+ 5. [Frequently Asked Questions](http://api.mongodb.org/ruby/current/file.FAQ.html).
12
+ 6. [History](http://api.mongodb.org/ruby/current/file.HISTORY.html).
13
+ 7. [Credits](http://api.mongodb.org/ruby/current/file.CREDITS.html).
14
+
15
+ Here's a quick code sample. Again, see the [MongoDB Ruby Tutorial](http://api.mongodb.org/ruby/current/file.TUTORIAL.html)
16
+ for much more:
17
+
18
+ require 'rubygems'
19
+ require 'mongo'
20
+ include Mongo
21
+
22
+ db = Connection.new.db('sample-db')
23
+ coll = db.collection('test')
24
+
25
+ coll.remove
26
+ 3.times do |i|
27
+ coll.insert({'a' => i+1})
28
+ end
29
+ puts "There are #{coll.count()} records. Here they are:"
30
+ coll.find().each { |doc| puts doc.inspect }
31
+
32
+ # Installation
33
+
34
+ ### Ruby Versions
35
+
36
+ The driver works and is consistently tested on Ruby 1.8.6, 1.8.7, and 1.9.2, and JRuby 1.5.1.
37
+
38
+ Note that if you're on 1.8.7, be sure that you're using a patchlevel >= 249. There
39
+ are some IO bugs in earlier versions.
40
+
41
+ ### Gems
42
+
43
+ The driver's gems are hosted at [Rubygems.org](http://rubygems.org). Make sure you're
44
+ using the latest version of rubygems:
45
+
46
+ $ gem update --system
47
+
48
+ Then you can install the mongo gem as follows:
49
+
50
+ $ gem install mongo
51
+
52
+ The driver also requires the bson gem:
53
+
54
+ $ gem install bson
55
+
56
+ And for a significant performance boost, you'll want to install the C extensions:
57
+
58
+ $ gem install bson_ext
59
+
60
+ Note that bson_ext isn't used with JRuby. Instead, some native Java extensions are bundled with the bson gem.
61
+ If you ever need to modify these extenions, you can recompile with the following rake task:
62
+
63
+ $ rake build:java
64
+
65
+ ### From the GitHub source
66
+
67
+ The source code is available at http://github.com/mongodb/mongo-ruby-driver.
68
+ You can either clone the git repository or download a tarball or zip file.
69
+ Once you have the source, you can use it from wherever you downloaded it or
70
+ you can install it as a gem from the source by typing
71
+
72
+ $ rake gem:install
73
+
74
+ To install the C extensions from source, type this instead:
75
+
76
+ $ rake gem:install_extensions
77
+
78
+ That's all there is to it!
79
+
80
+ # Examples
81
+
82
+ For extensive examples, see the [MongoDB Ruby Tutorial](http://www.mongodb.org/display/DOCS/Ruby+Tutorial).
83
+
84
+ Bundled with the driver are many examples, located in the "docs/examples" subdirectory. Samples include using
85
+ the driver and using the GridFS class GridStore. MongoDB must be running for
86
+ these examples to work, of course.
87
+
88
+ Here's how to start MongoDB and run the "simple.rb" example:
89
+
90
+ $ cd path/to/mongo
91
+ $ ./mongod run
92
+ ... then in another window ...
93
+ $ cd path/to/mongo-ruby-driver
94
+ $ ruby docs/examples/simple.rb
95
+
96
+ See also the test code, especially test/test_db_api.rb.
97
+
98
+ # GridFS
99
+
100
+ The Ruby driver include two abstractions for storing large files: Grid and GridFileSystem.
101
+ The Grid class is a Ruby implementation of MongoDB's GridFS file storage
102
+ specification. GridFileSystem is essentailly the same, but provides a more filesystem-like API
103
+ and assumes that filenames are unique.
104
+
105
+ An instance of both classes represents an individual file store. See the API reference
106
+ for details, and see examples/gridfs.rb for code that uses many of the Grid
107
+ features (metadata, content type, seek, tell, etc).
108
+
109
+ Examples:
110
+ # Write a file on disk to the Grid
111
+ file = File.open('image.jpg')
112
+ grid = Grid.new(db)
113
+ id = grid.put(file)
114
+
115
+ # Retrieve the file
116
+ file = grid.get(id)
117
+ file.read
118
+
119
+ # Get all the file's metata
120
+ file.filename
121
+ file.content_type
122
+ file.metadata
123
+
124
+ # Notes
125
+
126
+ ## Thread Safety
127
+
128
+ The driver is thread-safe.
129
+
130
+ ## Connection Pooling
131
+
132
+ The driver implements connection pooling. By default, only one
133
+ socket connection will be opened to MongoDB. However, if you're running a
134
+ multi-threaded application, you can specify a maximum pool size and a maximum
135
+ timeout for waiting for old connections to be released to the pool.
136
+
137
+ To set up a pooled connection to a single MongoDB instance:
138
+
139
+ @conn = Connection.new("localhost", 27017, :pool_size => 5, :timeout => 5)
140
+
141
+ Though the pooling architecture will undoubtedly evolve, it currently owes much credit
142
+ to the connection pooling implementations in ActiveRecord and PyMongo.
143
+
144
+ ## Using with Phusion Passenger and Unicorn
145
+
146
+ When Passenger and Unicorn are in smart spawning mode you need to be sure that child
147
+ processes will create a new connection to the database. In Passenger, this can be handled like so:
148
+
149
+ if defined?(PhusionPassenger)
150
+ PhusionPassenger.on_event(:starting_worker_process) do |forked|
151
+ if forked
152
+ # Reset all connection objects. How you do this depends on where
153
+ # you keep your connection object. In any case, call the #connect
154
+ # method on the connection object. For example:
155
+ # CONN.connect
156
+ #
157
+ # If you're using MongoMapper:
158
+ # MongoMapper.connection.connect
159
+ end
160
+ end
161
+ end
162
+
163
+ In Unicorn, add this to your unicorn.rb file:
164
+
165
+ after_fork do |server, worker|
166
+ # Handle reconnection
167
+ end
168
+
169
+ The above code should be put into a Rails initializer or similar initialization script.
170
+
171
+ ## String Encoding
172
+
173
+ The BSON ("Binary JSON") format used to communicate with Mongo requires that
174
+ strings be UTF-8 (http://en.wikipedia.org/wiki/UTF-8).
175
+
176
+ Ruby 1.9 has built-in character encoding support. All strings sent to Mongo
177
+ and received from Mongo are converted to UTF-8 when necessary, and strings
178
+ read from Mongo will have their character encodings set to UTF-8.
179
+
180
+ When used with Ruby 1.8, the bytes in each string are written to and read from
181
+ Mongo as is. If the string is ASCII, all is well, because ASCII is a subset of
182
+ UTF-8. If the string is not ASCII, it may not be a well-formed UTF-8
183
+ string.
184
+
185
+ ## Primary Keys
186
+
187
+ The `_id` field is a primary key. It is treated specially by the database, and
188
+ its use makes many operations more efficient. The value of an _id may be of
189
+ any type. The database itself inserts an _id value if none is specified when
190
+ a record is inserted.
191
+
192
+ ### Primary Key Factories
193
+
194
+ A primary key factory is a class you supply to a DB object that knows how to
195
+ generate _id values. If you want to control _id values or even their types,
196
+ using a PK factory lets you do so.
197
+
198
+ You can tell the Ruby Mongo driver how to create primary keys by passing in
199
+ the :pk option to the Connection#db method.
200
+
201
+ db = Mongo::Connection.new.db('dbname', :pk => MyPKFactory.new)
202
+
203
+ A primary key factory object must respond to :create_pk, which should
204
+ take a hash and return a hash which merges the original hash with any
205
+ primary key fields the factory wishes to inject.
206
+
207
+ NOTE: if the object already has a primary key, the factory should not
208
+ inject a new key; this means that the object may already exist in the
209
+ database. The idea here is that whenever a record is inserted, the
210
+ :pk object's +create_pk+ method will be called and the new hash
211
+ returned will be inserted.
212
+
213
+ Here is a sample primary key factory, taken from the tests:
214
+
215
+ class TestPKFactory
216
+ def create_pk(row)
217
+ row['_id'] ||= Mongo::ObjectID.new
218
+ row
219
+ end
220
+ end
221
+
222
+ Here's a slightly more sophisticated one that handles both symbol and string
223
+ keys. This is the PKFactory that comes with the MongoRecord code (an
224
+ ActiveRecord-like framework for non-Rails apps) and the AR Mongo adapter code
225
+ (for Rails):
226
+
227
+ class PKFactory
228
+ def create_pk(row)
229
+ return row if row[:_id]
230
+ row.delete(:_id) # in case it exists but the value is nil
231
+ row['_id'] ||= Mongo::ObjectID.new
232
+ row
233
+ end
234
+ end
235
+
236
+ A database's PK factory object may be set either when a DB object is created
237
+ or immediately after you obtain it, but only once. The only reason it is
238
+ changeable at all is so that libraries such as MongoRecord that use this
239
+ driver can set the PK factory after obtaining the database but before using it
240
+ for the first time.
241
+
242
+ ## The DB Class
243
+
244
+ ### Strict mode
245
+
246
+ Each database has an optional strict mode. If strict mode is on, then asking
247
+ for a collection that does not exist will raise an error, as will asking to
248
+ create a collection that already exists. Note that both these operations are
249
+ completely harmless; strict mode is a programmer convenience only.
250
+
251
+ To turn on strict mode, either pass in :strict => true when obtaining a DB
252
+ object or call the `:strict=` method:
253
+
254
+ db = Connection.new.db('dbname', :strict => true)
255
+ # I'm feeling lax
256
+ db.strict = false
257
+ # No, I'm not!
258
+ db.strict = true
259
+
260
+ The method DB#strict? returns the current value of that flag.
261
+
262
+ ## Cursors
263
+
264
+ Notes:
265
+
266
+ * Cursors are enumerable (and have a #to_a method).
267
+
268
+ * The query doesn't get run until you actually attempt to retrieve data from a
269
+ cursor.
270
+
271
+ * Cursors will timeout on the server after 10 minutes. If you need to keep a cursor
272
+ open for more than 10 minutes, specify `:timeout => false` when you create the cursor.
273
+
274
+
275
+ # Testing
276
+
277
+ If you have the source code, you can run the tests.
278
+
279
+ $ rake test:c
280
+
281
+ If you want to test the basic Ruby encoder, without the C extension, or if you're running JRuby:
282
+
283
+ $ rake test:ruby
284
+
285
+ These will run both unit and functional tests. To run these tests alone:
286
+
287
+ $ rake test:unit
288
+ $ rake test:functional
289
+
290
+ To run any individual rake tasks with the C extension enabled, just pass C_EXT=true to the task:
291
+
292
+ $ rake test:unit C_EXT=true
293
+
294
+ If you want to test replica set, you can run the following tests
295
+ individually:
296
+
297
+ $ rake test:replica_set_count
298
+ $ rake test:replica_set_insert
299
+ $ rake test:replica_set_query
300
+
301
+ ### Shoulda and Mocha
302
+
303
+ Running the test suite requires shoulda and mocha. You can install them as follows:
304
+
305
+ $ gem install shoulda
306
+ $ gem install mocha
307
+
308
+ The tests assume that the Mongo database is running on the default port. You
309
+ can override the default host (localhost) and port (Connection::DEFAULT_PORT) by
310
+ using the environment variables MONGO_RUBY_DRIVER_HOST and
311
+ MONGO_RUBY_DRIVER_PORT.
312
+
313
+ # Documentation
314
+
315
+ This documentation is available online at [http://api.mongodb.org/ruby](http://api.mongodb.org/ruby). You can
316
+ generate the documentation if you have the source by typing
317
+
318
+ $ rake ydoc
319
+
320
+ Then open the file +ydoc/index.html+.
321
+
322
+ # Release Notes
323
+
324
+ See HISTORY.
325
+
326
+ # Credits
327
+
328
+ See CREDITS.
329
+
330
+ # License
331
+
332
+ Copyright 2008-2010 10gen Inc.
333
+
334
+ Licensed under the Apache License, Version 2.0 (the "License");
335
+ you may not use this file except in compliance with the License.
336
+ You may obtain a copy of the License at
337
+
338
+ http://www.apache.org/licenses/LICENSE-2.0
339
+
340
+ Unless required by applicable law or agreed to in writing, software
341
+ distributed under the License is distributed on an "AS IS" BASIS,
342
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
343
+ See the License for the specific language governing permissions and
344
+ limitations under the License.