mongo-lyon 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
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/Rakefile ADDED
@@ -0,0 +1,202 @@
1
+ # -*- mode: ruby; -*-
2
+ require 'rubygems'
3
+ require 'rubygems/specification'
4
+ require 'fileutils'
5
+ require 'rake'
6
+ require 'rake/testtask'
7
+ require 'rake/gempackagetask'
8
+ begin
9
+ require 'rake/contrib/rubyforgepublisher'
10
+ rescue LoadError
11
+ end
12
+ require 'rbconfig'
13
+ include Config
14
+ ENV['TEST_MODE'] = 'TRUE'
15
+
16
+ task :java do
17
+ Rake::Task['build:java'].invoke
18
+ Rake::Task['test:ruby'].invoke
19
+ end
20
+
21
+ namespace :build do
22
+ desc "Build the java extensions."
23
+ task :java do
24
+ puts "Building Java extensions..."
25
+ java_dir = File.join(File.dirname(__FILE__), 'ext', 'java')
26
+ jar_dir = File.join(java_dir, 'jar')
27
+
28
+ jruby_jar = File.join(jar_dir, 'jruby.jar')
29
+ mongo_jar = File.join(jar_dir, 'mongo-2.4.jar')
30
+ bson_jar = File.join(jar_dir, 'bson-2.2.jar')
31
+
32
+ src_base = File.join(java_dir, 'src')
33
+
34
+ system("javac -Xlint:unchecked -classpath #{jruby_jar}:#{mongo_jar}:#{bson_jar} #{File.join(src_base, 'org', 'jbson', '*.java')}")
35
+ system("cd #{src_base} && jar cf #{File.join(jar_dir, 'jbson.jar')} #{File.join('.', 'org', 'jbson', '*.class')}")
36
+ end
37
+ end
38
+
39
+ desc "Test the MongoDB Ruby driver."
40
+ task :test do
41
+ puts "\nTo test the driver with the C-extensions:\nrake test:c\n\n"
42
+ puts "To test the pure ruby driver: \nrake test:ruby\n\n"
43
+ end
44
+
45
+ namespace :test do
46
+
47
+ desc "Test the driver with the C extension enabled."
48
+ task :c do
49
+ ENV['C_EXT'] = 'TRUE'
50
+ if ENV['TEST']
51
+ Rake::Task['test:functional'].invoke
52
+ else
53
+ Rake::Task['test:unit'].invoke
54
+ Rake::Task['test:functional'].invoke
55
+ Rake::Task['test:bson'].invoke
56
+ Rake::Task['test:pooled_threading'].invoke
57
+ Rake::Task['test:drop_databases'].invoke
58
+ end
59
+ ENV['C_EXT'] = nil
60
+ end
61
+
62
+ desc "Test the driver using pure ruby (no C extension)"
63
+ task :ruby do
64
+ ENV['C_EXT'] = nil
65
+ if ENV['TEST']
66
+ Rake::Task['test:functional'].invoke
67
+ else
68
+ Rake::Task['test:unit'].invoke
69
+ Rake::Task['test:functional'].invoke
70
+ Rake::Task['test:bson'].invoke
71
+ Rake::Task['test:pooled_threading'].invoke
72
+ Rake::Task['test:drop_databases'].invoke
73
+ end
74
+ end
75
+
76
+ desc "Run the replica set test suite"
77
+ Rake::TestTask.new(:rs) do |t|
78
+ t.test_files = FileList['test/replica_sets/*_test.rb']
79
+ t.verbose = true
80
+ end
81
+
82
+ Rake::TestTask.new(:unit) do |t|
83
+ t.test_files = FileList['test/unit/*_test.rb']
84
+ t.verbose = true
85
+ end
86
+
87
+ Rake::TestTask.new(:functional) do |t|
88
+ t.test_files = FileList['test/*_test.rb']
89
+ t.verbose = true
90
+ end
91
+
92
+ Rake::TestTask.new(:pooled_threading) do |t|
93
+ t.test_files = FileList['test/threading/*_test.rb']
94
+ t.verbose = true
95
+ end
96
+
97
+ Rake::TestTask.new(:auto_reconnect) do |t|
98
+ t.test_files = FileList['test/auxillary/autoreconnect_test.rb']
99
+ t.verbose = true
100
+ end
101
+
102
+ Rake::TestTask.new(:authentication) do |t|
103
+ t.test_files = FileList['test/auxillary/authentication_test.rb']
104
+ t.verbose = true
105
+ end
106
+
107
+ Rake::TestTask.new(:new_features) do |t|
108
+ t.test_files = FileList['test/auxillary/1.4_features.rb']
109
+ t.verbose = true
110
+ end
111
+
112
+ Rake::TestTask.new(:bson) do |t|
113
+ t.test_files = FileList['test/bson/*_test.rb']
114
+ t.verbose = true
115
+ end
116
+
117
+ task :drop_databases do |t|
118
+ puts "Dropping test databases..."
119
+ require './lib/mongo'
120
+ con = Mongo::Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
121
+ ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Connection::DEFAULT_PORT)
122
+ con.database_names.each do |name|
123
+ con.drop_database(name) if name =~ /^ruby-test/
124
+ end
125
+ end
126
+ end
127
+
128
+ desc "Generate RDOC documentation"
129
+ task :rdoc do
130
+ version = eval(File.read("mongo.gemspec")).version
131
+ out = File.join('html', version.to_s)
132
+ FileUtils.rm_rf('html')
133
+ system "rdoc --main README.md --op #{out} --inline-source --quiet README.md `find lib -name '*.rb'`"
134
+ end
135
+
136
+ desc "Generate YARD documentation"
137
+ task :ydoc do
138
+ require File.join(File.dirname(__FILE__), 'lib', 'mongo')
139
+ out = File.join('ydoc', Mongo::VERSION)
140
+ FileUtils.rm_rf('ydoc')
141
+ system "yardoc lib/**/*.rb lib/mongo/**/*.rb lib/bson/**/*.rb -e yard/yard_ext.rb -p yard/templates -o #{out} --title MongoRuby-#{Mongo::VERSION} --files docs/TUTORIAL.md,docs/GridFS.md,docs/FAQ.md,docs/REPLICA_SETS.md,docs/WRITE_CONCERN.md,docs/HISTORY.md,docs/CREDITS.md,docs/1.0_UPGRADE.md"
142
+ end
143
+
144
+ namespace :bamboo do
145
+ namespace :test do
146
+ task :ruby do
147
+ Rake::Task['test:ruby'].invoke
148
+ end
149
+
150
+ task :c do
151
+ Rake::Task['gem:install_extensions'].invoke
152
+ Rake::Task['test:c'].invoke
153
+ end
154
+ end
155
+ end
156
+
157
+ namespace :gem do
158
+
159
+ desc "Install the gem locally"
160
+ task :install do
161
+ sh "gem build bson.gemspec"
162
+ sh "gem install --no-rdoc --no-ri bson-*.gem"
163
+
164
+ sh "gem build mongo.gemspec"
165
+ sh "gem install --no-rdoc --no-ri mongo-*.gem"
166
+
167
+ sh "rm mongo-*.gem"
168
+ sh "rm bson-*.gem"
169
+ end
170
+
171
+ desc "Install the optional c extensions"
172
+ task :install_extensions do
173
+ sh "gem build bson_ext.gemspec"
174
+ sh "gem install --no-rdoc --no-ri bson_ext-*.gem"
175
+ sh "rm bson_ext-*.gem"
176
+ end
177
+
178
+ desc "Build all gems"
179
+ task :build_all do
180
+ sh "gem build mongo.gemspec"
181
+ sh "gem build bson.gemspec"
182
+ sh "gem build bson.java.gemspec"
183
+ sh "gem build bson_ext.gemspec"
184
+ end
185
+
186
+ end
187
+
188
+ namespace :ci do
189
+ namespace :test do
190
+ task :c do
191
+ Rake::Task['gem:install'].invoke
192
+ Rake::Task['gem:install_extensions'].invoke
193
+ Rake::Task['test:c'].invoke
194
+ end
195
+ end
196
+ end
197
+
198
+ task :default => :list
199
+
200
+ task :list do
201
+ system 'rake -T'
202
+ end
data/bin/mongo_console ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ org_argv = ARGV.dup
3
+ ARGV.clear
4
+
5
+ require 'irb'
6
+
7
+ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
8
+ require 'mongo'
9
+
10
+ include Mongo
11
+
12
+ unix_socket_path = org_argv[0] || ENV['MONGO_RUBY_DRIVER_UNIX_SOCKET_PATH']
13
+
14
+ if File.exists? unix_socket_path
15
+ dbnm = org_argv[1] || ENV['MONGO_RUBY_DRIVER_DB'] || 'ruby-mongo-console'
16
+ else
17
+ unix_socket_path = nil
18
+ host = org_argv[0] || ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
19
+ port = org_argv[1] || ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
20
+ dbnm = org_argv[2] || ENV['MONGO_RUBY_DRIVER_DB'] || 'ruby-mongo-console'
21
+ end
22
+
23
+ if unix_socket_path
24
+ puts "Connecting to #{unix_socket_path} (CONN) on with database #{dbnm} (DB)"
25
+ CONN = Connection.new(:socket => unix_socket_path)
26
+ else
27
+ puts "Connecting to #{host}:#{port} (CONN) on with database #{dbnm} (DB)"
28
+ CONN = Connection.new(host, port)
29
+ end
30
+
31
+ DB = CONN.db(dbnm)
32
+
33
+ puts "Starting IRB session..."
34
+ IRB.start(__FILE__)
@@ -0,0 +1,21 @@
1
+ You can upgrade freely from v0.20 to v1.0.
2
+
3
+ However, if you're running a version < 0.20, upgrade to 0.20
4
+ before upgrading to 1.0.
5
+
6
+ The upgrade to 0.20 requires some minor code upgrades.
7
+
8
+ 1. Note the exception changes in HISTORY. Certain exceptions are now scoped under the BSON
9
+ module; if you're catching these, you will need to modify your code.
10
+
11
+ 2. The BSON types are now scoped under the BSON module.
12
+
13
+ 3. Note that mongo_ext no longer exists. The new gems are bson and bson_ext.
14
+
15
+ 4. Indexes on GridFS chunks collections should be unique. If you have existing GridFS
16
+ collections, you should drop the current index and replace with a unique one. Before you do this,
17
+ make sure that index doesn't exist; no need to go through process unnecessarily.
18
+ If you do need to create the index, once you have the chunks collection, here are the commands you can run:
19
+
20
+ @chunks.drop_index('files_id_1_n_1')
21
+ @chunks.create_index([['files_id', Mongo::ASCENDING], ['n', Mongo::ASCENDING]], :unique => true)
data/docs/CREDITS.md ADDED
@@ -0,0 +1,123 @@
1
+ # Credits
2
+
3
+ Adrian Madrid, aemadrid@gmail.com
4
+
5
+ * bin/mongo_console
6
+ * examples/benchmarks.rb
7
+ * examples/irb.rb
8
+ * Modifications to examples/simple.rb
9
+ * Found plenty of bugs and missing features.
10
+ * Ruby 1.9 support.
11
+ * Gem support.
12
+ * Many other code suggestions and improvements.
13
+
14
+ Aman Gupta, aman@tmm1.net
15
+
16
+ * Collection#save
17
+ * Noted bug in returning query batch size.
18
+
19
+ Jon Crosby, jon@joncrosby.me
20
+
21
+ * Some code clean-up
22
+
23
+ John Nunemaker, http://railstips.org
24
+
25
+ * Collection#create_index takes symbols as well as strings
26
+ * Fix for Collection#save
27
+ * Add logger convenience methods to connection and database
28
+
29
+ David James, djames@sunlightfoundation.com
30
+
31
+ * Fix dates to return as UTC
32
+
33
+ Paul Dlug, paul.dlug@gmail.com
34
+
35
+ * Generate _id on the client side if not provided
36
+ * Collection#insert and Collection#save return _id
37
+
38
+ Durran Jordan, durran@gmail.com
39
+
40
+ * DB#collections
41
+ * Support for specifying sort order as array of [key, direction] pairs
42
+ * OrderedHash#update aliases to merge!
43
+
44
+ Cyril Mougel, cyril.mougel@gmail.com
45
+
46
+ * Initial logging support
47
+ * Test case
48
+
49
+ Jack Chen, chendo on github
50
+
51
+ * Test case + fix for deserializing pre-epoch Time instances
52
+
53
+ Michael Bernstein, mrb on github
54
+
55
+ * Cursor#sort
56
+
57
+ Paulo Ahahgon, pahagon on github
58
+
59
+ * removed hard limit
60
+
61
+ Les Hill, leshill on github
62
+
63
+ * OrderedHash#each returns self
64
+
65
+ Sean Cribbs, seancribbs on github
66
+
67
+ * Modified standard_benchmark to allow profiling
68
+ * C ext for faster ObjectID creation
69
+
70
+ Sunny Hirai
71
+
72
+ * Suggested hashcode fix for Mongo::ObjectID
73
+ * Noted index ordering bug.
74
+ * GridFS performance boost
75
+
76
+ Christos Trochalakis
77
+
78
+ * Added map/reduce helper
79
+
80
+ Blythe Dunham
81
+
82
+ * Added finalize option to map/reduce
83
+
84
+ Matt Powell (fauxparse)
85
+
86
+ * Added GridStore#mv
87
+
88
+ Patrick Collison
89
+
90
+ * Added safe mode for Collection#remove
91
+
92
+ Chuck Remes
93
+
94
+ * Extraction of BSON into separate gems
95
+ * Extensions compile on Rubinius
96
+ * Performance improvements for INT in C extensions
97
+ * Performance improvements for JRuby BSON encoder and callback classes
98
+
99
+ Dmitrii Golub (Houdini) and Jacques Crocker (railsjedi)
100
+
101
+ * Support open to exclude fields on query
102
+
103
+ dfitzgibbon
104
+
105
+ * patch for ensuring bson_ext compatibility with early release of Ruby 1.8.5
106
+
107
+ Matt Taylor
108
+
109
+ * Noticed excessive calls to ObjectId#to_s. As a result, stopped creating
110
+ log messages when no logger was passed to Mongo::Connection. Resulted in a significant
111
+ performance improvement.
112
+
113
+ Hongli Lai (Phusion)
114
+
115
+ * Significant performance improvements. See commits.
116
+
117
+ Mislav Marohnić
118
+
119
+ * Replaced returning with each_with_object
120
+
121
+ Alex Stupka
122
+
123
+ * Replica set port bug
data/docs/FAQ.md ADDED
@@ -0,0 +1,116 @@
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].