mongo 2.14.0 → 2.15.0.alpha

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 (230) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +4 -1
  5. data/Rakefile +8 -15
  6. data/lib/mongo.rb +23 -0
  7. data/lib/mongo/auth/aws/conversation.rb +1 -4
  8. data/lib/mongo/auth/base.rb +13 -7
  9. data/lib/mongo/auth/conversation_base.rb +32 -0
  10. data/lib/mongo/auth/cr/conversation.rb +6 -29
  11. data/lib/mongo/auth/gssapi/conversation.rb +4 -15
  12. data/lib/mongo/auth/ldap/conversation.rb +3 -14
  13. data/lib/mongo/auth/sasl_conversation_base.rb +1 -13
  14. data/lib/mongo/auth/scram_conversation_base.rb +7 -34
  15. data/lib/mongo/auth/user/view.rb +16 -9
  16. data/lib/mongo/auth/x509/conversation.rb +4 -25
  17. data/lib/mongo/background_thread.rb +11 -0
  18. data/lib/mongo/bulk_write.rb +21 -18
  19. data/lib/mongo/client.rb +82 -6
  20. data/lib/mongo/cluster.rb +19 -28
  21. data/lib/mongo/cluster/reapers/cursor_reaper.rb +6 -2
  22. data/lib/mongo/cluster/sdam_flow.rb +14 -0
  23. data/lib/mongo/collection.rb +8 -6
  24. data/lib/mongo/collection/view/aggregation.rb +1 -1
  25. data/lib/mongo/collection/view/change_stream.rb +1 -1
  26. data/lib/mongo/collection/view/iterable.rb +1 -1
  27. data/lib/mongo/collection/view/map_reduce.rb +2 -2
  28. data/lib/mongo/collection/view/readable.rb +42 -20
  29. data/lib/mongo/collection/view/writable.rb +14 -14
  30. data/lib/mongo/cursor.rb +2 -2
  31. data/lib/mongo/database.rb +22 -5
  32. data/lib/mongo/database/view.rb +1 -1
  33. data/lib/mongo/error.rb +9 -1
  34. data/lib/mongo/error/bulk_write_error.rb +17 -3
  35. data/lib/mongo/error/internal_driver_error.rb +22 -0
  36. data/lib/mongo/error/operation_failure.rb +21 -2
  37. data/lib/mongo/error/parser.rb +65 -12
  38. data/lib/mongo/error/server_api_conflict.rb +23 -0
  39. data/lib/mongo/error/server_api_not_supported.rb +24 -0
  40. data/lib/mongo/error/unmet_dependency.rb +21 -0
  41. data/lib/mongo/grid/fs_bucket.rb +37 -37
  42. data/lib/mongo/index/view.rb +21 -11
  43. data/lib/mongo/monitoring.rb +13 -4
  44. data/lib/mongo/monitoring/event/server_heartbeat_failed.rb +27 -16
  45. data/lib/mongo/monitoring/event/server_heartbeat_succeeded.rb +26 -15
  46. data/lib/mongo/operation.rb +2 -2
  47. data/lib/mongo/operation/collections_info.rb +18 -1
  48. data/lib/mongo/operation/collections_info/command.rb +2 -2
  49. data/lib/mongo/operation/context.rb +99 -0
  50. data/lib/mongo/operation/indexes.rb +15 -1
  51. data/lib/mongo/operation/insert/command.rb +2 -2
  52. data/lib/mongo/operation/insert/legacy.rb +2 -2
  53. data/lib/mongo/operation/insert/op_msg.rb +2 -2
  54. data/lib/mongo/operation/list_collections/result.rb +4 -1
  55. data/lib/mongo/operation/result.rb +2 -0
  56. data/lib/mongo/operation/shared/executable.rb +24 -14
  57. data/lib/mongo/operation/shared/executable_no_validate.rb +2 -2
  58. data/lib/mongo/operation/shared/op_msg_or_command.rb +1 -7
  59. data/lib/mongo/operation/shared/op_msg_or_find_command.rb +1 -7
  60. data/lib/mongo/operation/shared/polymorphic_operation.rb +39 -0
  61. data/lib/mongo/operation/shared/response_handling.rb +23 -23
  62. data/lib/mongo/operation/shared/sessions_supported.rb +13 -2
  63. data/lib/mongo/operation/shared/write.rb +8 -18
  64. data/lib/mongo/protocol/compressed.rb +51 -5
  65. data/lib/mongo/protocol/message.rb +20 -2
  66. data/lib/mongo/protocol/msg.rb +36 -11
  67. data/lib/mongo/query_cache.rb +30 -0
  68. data/lib/mongo/retryable.rb +1 -1
  69. data/lib/mongo/server.rb +7 -15
  70. data/lib/mongo/server/app_metadata.rb +52 -18
  71. data/lib/mongo/server/connection.rb +5 -0
  72. data/lib/mongo/server/connection_base.rb +13 -10
  73. data/lib/mongo/server/connection_pool.rb +6 -4
  74. data/lib/mongo/server/description.rb +4 -0
  75. data/lib/mongo/server/description/features.rb +9 -8
  76. data/lib/mongo/server/monitor.rb +20 -1
  77. data/lib/mongo/server/monitor/app_metadata.rb +1 -1
  78. data/lib/mongo/server/monitor/connection.rb +9 -10
  79. data/lib/mongo/server/pending_connection.rb +24 -6
  80. data/lib/mongo/server/push_monitor.rb +11 -1
  81. data/lib/mongo/session.rb +2 -2
  82. data/lib/mongo/session/session_pool.rb +4 -2
  83. data/lib/mongo/socket.rb +29 -4
  84. data/lib/mongo/socket/ssl.rb +8 -0
  85. data/lib/mongo/srv/monitor.rb +0 -11
  86. data/lib/mongo/uri/options_mapper.rb +38 -0
  87. data/lib/mongo/utils.rb +15 -0
  88. data/lib/mongo/version.rb +1 -1
  89. data/spec/README.md +24 -1
  90. data/spec/integration/auth_spec.rb +25 -15
  91. data/spec/integration/bulk_write_error_message_spec.rb +41 -0
  92. data/spec/integration/change_stream_spec.rb +4 -4
  93. data/spec/integration/command_monitoring_spec.rb +2 -2
  94. data/spec/integration/connection_spec.rb +2 -0
  95. data/spec/integration/docs_examples_spec.rb +8 -1
  96. data/spec/integration/fork_reconnect_spec.rb +4 -1
  97. data/spec/integration/ocsp_verifier_spec.rb +13 -7
  98. data/spec/integration/operation_failure_code_spec.rb +1 -1
  99. data/spec/integration/operation_failure_message_spec.rb +90 -0
  100. data/spec/integration/reconnect_spec.rb +1 -1
  101. data/spec/integration/sdam_error_handling_spec.rb +1 -1
  102. data/spec/integration/sdam_events_spec.rb +3 -5
  103. data/spec/integration/snappy_compression_spec.rb +25 -0
  104. data/spec/integration/srv_monitoring_spec.rb +1 -1
  105. data/spec/integration/transactions_examples_spec.rb +6 -0
  106. data/spec/integration/zlib_compression_spec.rb +1 -1
  107. data/spec/integration/zstd_compression_spec.rb +26 -0
  108. data/spec/lite_spec_helper.rb +7 -1
  109. data/spec/mongo/address_spec.rb +15 -11
  110. data/spec/mongo/auth/ldap/conversation_spec.rb +1 -1
  111. data/spec/mongo/auth/ldap_spec.rb +5 -1
  112. data/spec/mongo/auth/scram_negotiation_spec.rb +1 -1
  113. data/spec/mongo/auth/scram_spec.rb +1 -1
  114. data/spec/mongo/auth/x509/conversation_spec.rb +3 -3
  115. data/spec/mongo/client_construction_spec.rb +207 -33
  116. data/spec/mongo/client_spec.rb +17 -0
  117. data/spec/mongo/cluster_spec.rb +3 -18
  118. data/spec/mongo/collection/view/explainable_spec.rb +1 -1
  119. data/spec/mongo/collection/view/readable_spec.rb +33 -19
  120. data/spec/mongo/collection_crud_spec.rb +4357 -0
  121. data/spec/mongo/collection_ddl_spec.rb +534 -0
  122. data/spec/mongo/collection_spec.rb +5 -4859
  123. data/spec/mongo/database_spec.rb +66 -4
  124. data/spec/mongo/error/bulk_write_error_spec.rb +3 -3
  125. data/spec/mongo/error/parser_spec.rb +37 -6
  126. data/spec/mongo/index/view_spec.rb +8 -2
  127. data/spec/mongo/monitoring/event/server_heartbeat_failed_spec.rb +1 -1
  128. data/spec/mongo/monitoring/event/server_heartbeat_succeeded_spec.rb +1 -1
  129. data/spec/mongo/operation/aggregate_spec.rb +2 -1
  130. data/spec/mongo/operation/collections_info_spec.rb +4 -1
  131. data/spec/mongo/operation/command_spec.rb +6 -3
  132. data/spec/mongo/operation/create_index_spec.rb +6 -3
  133. data/spec/mongo/operation/create_user_spec.rb +6 -3
  134. data/spec/mongo/operation/delete/bulk_spec.rb +9 -6
  135. data/spec/mongo/operation/delete_spec.rb +11 -7
  136. data/spec/mongo/operation/drop_index_spec.rb +6 -2
  137. data/spec/mongo/operation/find/legacy_spec.rb +3 -1
  138. data/spec/mongo/operation/get_more_spec.rb +3 -1
  139. data/spec/mongo/operation/indexes_spec.rb +5 -1
  140. data/spec/mongo/operation/insert/bulk_spec.rb +10 -7
  141. data/spec/mongo/operation/insert_spec.rb +15 -12
  142. data/spec/mongo/operation/map_reduce_spec.rb +5 -2
  143. data/spec/mongo/operation/remove_user_spec.rb +6 -3
  144. data/spec/mongo/operation/result_spec.rb +1 -1
  145. data/spec/mongo/operation/update/bulk_spec.rb +9 -6
  146. data/spec/mongo/operation/update_spec.rb +10 -7
  147. data/spec/mongo/operation/update_user_spec.rb +4 -1
  148. data/spec/mongo/protocol/compressed_spec.rb +26 -12
  149. data/spec/mongo/query_cache_middleware_spec.rb +55 -0
  150. data/spec/mongo/retryable_spec.rb +3 -2
  151. data/spec/mongo/server/app_metadata_spec.rb +2 -0
  152. data/spec/mongo/server/connection_pool/populator_spec.rb +3 -1
  153. data/spec/mongo/server/connection_pool_spec.rb +1 -1
  154. data/spec/mongo/server/connection_spec.rb +24 -17
  155. data/spec/mongo/server/monitor/connection_spec.rb +17 -7
  156. data/spec/mongo/server/monitor_spec.rb +9 -1
  157. data/spec/mongo/server_spec.rb +15 -2
  158. data/spec/mongo/socket/ssl_spec.rb +40 -0
  159. data/spec/mongo/socket_spec.rb +2 -2
  160. data/spec/mongo/tls_context_hooks_spec.rb +37 -0
  161. data/spec/runners/connection_string.rb +0 -4
  162. data/spec/runners/crud/requirement.rb +40 -3
  163. data/spec/runners/crud/verifier.rb +8 -0
  164. data/spec/runners/transactions/operation.rb +13 -2
  165. data/spec/runners/transactions/test.rb +1 -0
  166. data/spec/runners/unified.rb +96 -0
  167. data/spec/runners/unified/assertions.rb +249 -0
  168. data/spec/runners/unified/change_stream_operations.rb +26 -0
  169. data/spec/runners/unified/crud_operations.rb +199 -0
  170. data/spec/runners/unified/ddl_operations.rb +96 -0
  171. data/spec/runners/unified/entity_map.rb +39 -0
  172. data/spec/runners/unified/error.rb +25 -0
  173. data/spec/runners/unified/event_subscriber.rb +91 -0
  174. data/spec/runners/unified/exceptions.rb +21 -0
  175. data/spec/runners/unified/grid_fs_operations.rb +55 -0
  176. data/spec/runners/unified/support_operations.rb +250 -0
  177. data/spec/runners/unified/test.rb +393 -0
  178. data/spec/runners/unified/test_group.rb +28 -0
  179. data/spec/runners/unified/using_hash.rb +31 -0
  180. data/spec/shared/bin/get-mongodb-download-url +17 -0
  181. data/spec/shared/lib/mrss/cluster_config.rb +218 -0
  182. data/spec/shared/lib/mrss/constraints.rb +43 -0
  183. data/spec/shared/lib/mrss/docker_runner.rb +262 -0
  184. data/spec/shared/lib/mrss/server_version_registry.rb +112 -0
  185. data/spec/shared/lib/mrss/utils.rb +15 -0
  186. data/spec/shared/share/Dockerfile.erb +231 -0
  187. data/spec/shared/shlib/distro.sh +73 -0
  188. data/spec/shared/shlib/server.sh +290 -0
  189. data/spec/shared/shlib/set_env.sh +128 -0
  190. data/spec/solo/clean_exit_spec.rb +21 -0
  191. data/spec/spec_helper.rb +4 -1
  192. data/spec/spec_tests/crud_unified_spec.rb +10 -0
  193. data/spec/spec_tests/data/change_streams/change-streams.yml +0 -1
  194. data/spec/spec_tests/data/crud_unified/estimatedDocumentCount.yml +267 -0
  195. data/spec/spec_tests/data/retryable_reads/estimatedDocumentCount-4.9.yml +60 -0
  196. data/spec/spec_tests/data/retryable_reads/{estimatedDocumentCount.yml → estimatedDocumentCount-pre4.9.yml} +2 -0
  197. data/spec/spec_tests/data/retryable_reads/estimatedDocumentCount-serverErrors-4.9.yml +146 -0
  198. data/spec/spec_tests/data/retryable_reads/{estimatedDocumentCount-serverErrors.yml → estimatedDocumentCount-serverErrors-pre4.9.yml} +2 -0
  199. data/spec/spec_tests/data/retryable_reads/listIndexNames.yml +1 -1
  200. data/spec/spec_tests/data/unified/valid-fail/operation-failure.yml +31 -0
  201. data/spec/spec_tests/data/unified/valid-pass/poc-change-streams.yml +220 -0
  202. data/spec/spec_tests/data/unified/valid-pass/poc-command-monitoring.yml +102 -0
  203. data/spec/spec_tests/data/unified/valid-pass/poc-crud.yml +184 -0
  204. data/spec/spec_tests/data/unified/valid-pass/poc-gridfs.yml +155 -0
  205. data/spec/spec_tests/data/unified/valid-pass/poc-retryable-reads.yml +193 -0
  206. data/spec/spec_tests/data/unified/valid-pass/poc-retryable-writes.yml +210 -0
  207. data/spec/spec_tests/data/unified/valid-pass/poc-sessions.yml +215 -0
  208. data/spec/spec_tests/data/unified/valid-pass/poc-transactions-convenient-api.yml +235 -0
  209. data/spec/spec_tests/data/unified/valid-pass/poc-transactions-mongos-pin-auto.yml +169 -0
  210. data/spec/spec_tests/data/unified/valid-pass/poc-transactions.yml +170 -0
  211. data/spec/spec_tests/data/uri_options/compression-options.yml +1 -1
  212. data/spec/spec_tests/data/versioned_api/crud-api-version-1-strict.yml +416 -0
  213. data/spec/spec_tests/data/versioned_api/crud-api-version-1.yml +409 -0
  214. data/spec/spec_tests/data/versioned_api/runcommand-helper-no-api-version-declared.yml +67 -0
  215. data/spec/spec_tests/data/versioned_api/test-commands-deprecation-errors.yml +47 -0
  216. data/spec/spec_tests/data/versioned_api/test-commands-strict-mode.yml +44 -0
  217. data/spec/spec_tests/data/versioned_api/transaction-handling.yml +180 -0
  218. data/spec/spec_tests/unified_spec.rb +15 -0
  219. data/spec/spec_tests/uri_options_spec.rb +16 -0
  220. data/spec/spec_tests/versioned_api_spec.rb +10 -0
  221. data/spec/support/common_shortcuts.rb +15 -1
  222. data/spec/support/shared/session.rb +2 -2
  223. data/spec/support/spec_config.rb +46 -3
  224. data/spec/support/spec_setup.rb +48 -38
  225. data/spec/support/utils.rb +64 -3
  226. metadata +1104 -992
  227. metadata.gz.sig +0 -0
  228. data/lib/mongo/operation/shared/collections_info_or_list_collections.rb +0 -58
  229. data/lib/mongo/operation/shared/op_msg_or_list_indexes_command.rb +0 -47
  230. data/spec/support/cluster_config.rb +0 -207
@@ -178,6 +178,7 @@ class Mongo::Cluster
178
178
  raise ArgumentError, "Unknown topology #{topology.class}"
179
179
  end
180
180
 
181
+ verify_invariants
181
182
  commit_changes
182
183
  disconnect_servers
183
184
  end
@@ -363,6 +364,9 @@ class Mongo::Cluster
363
364
  end
364
365
  end
365
366
  end
367
+
368
+ verify_invariants
369
+
366
370
  added_servers
367
371
  end
368
372
 
@@ -599,5 +603,15 @@ class Mongo::Cluster
599
603
 
600
604
  @previous_server_descriptions != server_descriptions
601
605
  end
606
+
607
+ def verify_invariants
608
+ if Mongo::Lint.enabled?
609
+ if cluster.topology.single?
610
+ if cluster.servers_list.length > 1
611
+ raise Mongo::Error::LintError, "Trying to create a single topology with multiple servers: #{cluster.servers_list}"
612
+ end
613
+ end
614
+ end
615
+ end
602
616
  end
603
617
  end
@@ -254,8 +254,8 @@ module Mongo
254
254
  selector: operation,
255
255
  db_name: database.name,
256
256
  write_concern: write_concern,
257
- session: session
258
- }).execute(server, client: client)
257
+ session: session,
258
+ }).execute(server, context: Operation::Context.new(client: client, session: session))
259
259
  end
260
260
  end
261
261
 
@@ -287,8 +287,8 @@ module Mongo
287
287
  selector: { :drop => name },
288
288
  db_name: database.name,
289
289
  write_concern: write_concern,
290
- session: session
291
- }).execute(next_primary(nil, session), client: client)
290
+ session: session,
291
+ }).execute(next_primary(nil, session), context: Operation::Context.new(client: client, session: session))
292
292
  end
293
293
  rescue Error::OperationFailure => ex
294
294
  # NamespaceNotFound
@@ -579,8 +579,8 @@ module Mongo
579
579
  :options => opts,
580
580
  :id_generator => client.options[:id_generator],
581
581
  :session => session,
582
- :txn_num => txn_num
583
- ).execute(server, client: client)
582
+ :txn_num => txn_num,
583
+ ).execute(server, context: Operation::Context.new(client: client, session: session))
584
584
  end
585
585
  end
586
586
  end
@@ -593,6 +593,8 @@ module Mongo
593
593
  # @param [ Array<Hash> ] documents The documents to insert.
594
594
  # @param [ Hash ] options The insert options.
595
595
  #
596
+ # @option options [ true | false ] :ordered Whether the operations
597
+ # should be executed in order.
596
598
  # @option options [ Session ] :session The session to use for the operation.
597
599
  #
598
600
  # @return [ Result ] The database response wrapper.
@@ -134,7 +134,7 @@ module Mongo
134
134
  server = cluster.next_primary(nil, session)
135
135
  end
136
136
  validate_collation!(server)
137
- initial_query_op(session).execute(server, client: client)
137
+ initial_query_op(session).execute(server, context: Operation::Context.new(client: client, session: session))
138
138
  end
139
139
 
140
140
  def validate_collation!(server)
@@ -346,7 +346,7 @@ module Mongo
346
346
  end
347
347
 
348
348
  def send_initial_query(server, session)
349
- initial_query_op(session).execute(server, client: client)
349
+ initial_query_op(session).execute(server, context: Operation::Context.new(client: client, session: session))
350
350
  end
351
351
 
352
352
  def time_to_bson_timestamp(time)
@@ -157,7 +157,7 @@ module Mongo
157
157
 
158
158
  def send_initial_query(server, session = nil)
159
159
  validate_collation!(server, collation)
160
- initial_query_op(server, session).execute(server, client: client)
160
+ initial_query_op(server, session).execute(server, context: Operation::Context.new(client: client, session: session))
161
161
  end
162
162
 
163
163
  def use_query_cache?
@@ -242,7 +242,7 @@ module Mongo
242
242
  server = cluster.next_primary(nil, session)
243
243
  end
244
244
  validate_collation!(server)
245
- initial_query_op(session).execute(server, client: client)
245
+ initial_query_op(session).execute(server, context: Operation::Context.new(client: client, session: session))
246
246
  end
247
247
 
248
248
  def fetch_query_spec
@@ -262,7 +262,7 @@ module Mongo
262
262
  end
263
263
 
264
264
  def send_fetch_query(server, session)
265
- fetch_query_op(server, session).execute(server, client: client)
265
+ fetch_query_op(server, session).execute(server, context: Operation::Context.new(client: client, session: session))
266
266
  end
267
267
 
268
268
  def validate_collation!(server)
@@ -172,8 +172,8 @@ module Mongo
172
172
  :db_name => database.name,
173
173
  :options => {:limit => -1},
174
174
  :read => read_pref,
175
- :session => session
176
- ).execute(server, client: client)
175
+ :session => session,
176
+ ).execute(server, context: Operation::Context.new(client: client, session: session))
177
177
  end.n.to_i
178
178
  end
179
179
  end
@@ -230,24 +230,46 @@ module Mongo
230
230
  raise ArgumentError, "Cannot call estimated_document_count when querying with a filter"
231
231
  end
232
232
 
233
- cmd = { count: collection.name }
234
- cmd[:maxTimeMS] = opts[:max_time_ms] if opts[:max_time_ms]
235
- if read_concern
236
- cmd[:readConcern] = Options::Mapper.transform_values_to_strings(
237
- read_concern)
238
- end
239
233
  Mongo::Lint.validate_underscore_read_preference(opts[:read])
240
234
  read_pref = opts[:read] || read_preference
241
235
  selector = ServerSelector.get(read_pref || server_selector)
242
236
  with_session(opts) do |session|
237
+ context = Operation::Context.new(client: client, session: session)
243
238
  read_with_retry(session, selector) do |server|
244
- Operation::Count.new(
245
- selector: cmd,
246
- db_name: database.name,
247
- read: read_pref,
248
- session: session
249
- ).execute(server, client: client)
250
- end.n.to_i
239
+ if server.description.server_version_gte?('5.0')
240
+ pipeline = [
241
+ {'$collStats' => {'count' => {}}},
242
+ {'$group' => {'_id' => 1, 'n' => {'$sum' => '$count'}}},
243
+ ]
244
+ spec = Builder::Aggregation.new(pipeline, self, options.merge(session: session)).specification
245
+ result = Operation::Aggregate.new(spec).execute(server, context: context)
246
+ result.documents.first.fetch('n')
247
+ else
248
+ cmd = { count: collection.name }
249
+ cmd[:maxTimeMS] = opts[:max_time_ms] if opts[:max_time_ms]
250
+ if read_concern
251
+ cmd[:readConcern] = Options::Mapper.transform_values_to_strings(
252
+ read_concern)
253
+ end
254
+ result = Operation::Count.new(
255
+ selector: cmd,
256
+ db_name: database.name,
257
+ read: read_pref,
258
+ session: session,
259
+ ).execute(server, context: context)
260
+ result.n.to_i
261
+ end
262
+ end
263
+ end
264
+ rescue Error::OperationFailure => exc
265
+ if exc.code == 26
266
+ # NamespaceNotFound
267
+ # This should only happen with the aggregation pipeline path
268
+ # (server 4.9+). Previous servers should return 0 for nonexistent
269
+ # collections.
270
+ 0
271
+ else
272
+ raise
251
273
  end
252
274
  end
253
275
 
@@ -290,8 +312,8 @@ module Mongo
290
312
  :db_name => database.name,
291
313
  :options => {:limit => -1},
292
314
  :read => read_pref,
293
- :session => session
294
- }).execute(server, client: client)
315
+ :session => session,
316
+ }).execute(server, context: Operation::Context.new(client: client, session: session))
295
317
  end.first['values']
296
318
  end
297
319
  end
@@ -626,21 +648,21 @@ module Mongo
626
648
  :read_concern => read_concern,
627
649
  :session => session,
628
650
  }.merge!(options))
629
- cmd.execute(server, client: client).cursor_ids.map do |cursor_id|
651
+ cmd.execute(server, context: Operation::Context.new(client: client, session: session)).cursor_ids.map do |cursor_id|
630
652
  result = if server.with_connection { |connection| connection.features }.find_command_enabled?
631
653
  Operation::GetMore.new({
632
654
  :selector => {:getMore => BSON::Int64.new(cursor_id),
633
655
  :collection => collection.name},
634
656
  :db_name => database.name,
635
657
  :session => session,
636
- }).execute(server, client: client)
658
+ }).execute(server, context: Operation::Context.new(client: client, session: session))
637
659
  else
638
660
  Operation::GetMore.new({
639
661
  :to_return => 0,
640
662
  :cursor_id => BSON::Int64.new(cursor_id),
641
663
  :db_name => database.name,
642
664
  :coll_name => collection.name
643
- }).execute(server, client: client)
665
+ }).execute(server, context: Operation::Context.new(client: client, session: session))
644
666
  end
645
667
  Cursor.new(self, result, server, session: session)
646
668
  end
@@ -69,8 +69,8 @@ module Mongo
69
69
  :selector => cmd,
70
70
  :db_name => database.name,
71
71
  :session => session,
72
- :txn_num => txn_num
73
- ).execute(server, client: client)
72
+ :txn_num => txn_num,
73
+ ).execute(server, context: Operation::Context.new(client: client, session: session))
74
74
  end
75
75
  end.first['value']
76
76
  end
@@ -154,8 +154,8 @@ module Mongo
154
154
  :selector => cmd,
155
155
  :db_name => database.name,
156
156
  :session => session,
157
- :txn_num => txn_num
158
- ).execute(server, client: client)
157
+ :txn_num => txn_num,
158
+ ).execute(server, context: Operation::Context.new(client: client, session: session))
159
159
  end
160
160
  end.first['value']
161
161
  value unless value.nil? || value.empty?
@@ -198,8 +198,8 @@ module Mongo
198
198
  :coll_name => collection.name,
199
199
  :write_concern => write_concern,
200
200
  :bypass_document_validation => !!opts[:bypass_document_validation],
201
- :session => session
202
- ).execute(server, client: client)
201
+ :session => session,
202
+ ).execute(server, context: Operation::Context.new(client: client, session: session))
203
203
  end
204
204
  end
205
205
  end
@@ -242,8 +242,8 @@ module Mongo
242
242
  :write_concern => write_concern,
243
243
  :bypass_document_validation => !!opts[:bypass_document_validation],
244
244
  :session => session,
245
- :txn_num => txn_num
246
- ).execute(server, client: client)
245
+ :txn_num => txn_num,
246
+ ).execute(server, context: Operation::Context.new(client: client, session: session))
247
247
  end
248
248
  end
249
249
  end
@@ -298,8 +298,8 @@ module Mongo
298
298
  :write_concern => write_concern,
299
299
  :bypass_document_validation => !!opts[:bypass_document_validation],
300
300
  :session => session,
301
- :txn_num => txn_num
302
- ).execute(server, client: client)
301
+ :txn_num => txn_num,
302
+ ).execute(server, context: Operation::Context.new(client: client, session: session))
303
303
  end
304
304
  end
305
305
  end
@@ -355,8 +355,8 @@ module Mongo
355
355
  :coll_name => collection.name,
356
356
  :write_concern => write_concern,
357
357
  :bypass_document_validation => !!opts[:bypass_document_validation],
358
- :session => session
359
- ).execute(server, client: client)
358
+ :session => session,
359
+ ).execute(server, context: Operation::Context.new(client: client, session: session))
360
360
  end
361
361
  end
362
362
  end
@@ -412,8 +412,8 @@ module Mongo
412
412
  :write_concern => write_concern,
413
413
  :bypass_document_validation => !!opts[:bypass_document_validation],
414
414
  :session => session,
415
- :txn_num => txn_num
416
- ).execute(server, client: client)
415
+ :txn_num => txn_num,
416
+ ).execute(server, context: Operation::Context.new(client: client, session: session))
417
417
  end
418
418
  end
419
419
  end
data/lib/mongo/cursor.rb CHANGED
@@ -270,7 +270,7 @@ module Mongo
270
270
 
271
271
  unregister
272
272
  read_with_one_retry do
273
- kill_cursors_operation.execute(@server, client: client)
273
+ kill_cursors_operation.execute(@server, context: Operation::Context.new(client: client, session: @session))
274
274
  end
275
275
 
276
276
  nil
@@ -345,7 +345,7 @@ module Mongo
345
345
  # doing so may result in silent data loss, the driver no longer retries
346
346
  # getMore operations in any circumstance.
347
347
  # https://github.com/mongodb/specifications/blob/master/source/retryable-reads/retryable-reads.rst#qa
348
- process(get_more_operation.execute(@server, client: client))
348
+ process(get_more_operation.execute(@server, context: Operation::Context.new(client: client, session: @session)))
349
349
  end
350
350
 
351
351
  private
@@ -104,6 +104,9 @@ module Mongo
104
104
  #
105
105
  # @since 2.0.0
106
106
  def [](collection_name, options = {})
107
+ if options[:server_api]
108
+ raise ArgumentError, 'The :server_api option cannot be specified for collection objects. It can only be specified on Client level'
109
+ end
107
110
  Collection.new(self, collection_name, options)
108
111
  end
109
112
  alias_method :collection, :[]
@@ -219,7 +222,9 @@ module Mongo
219
222
  :session => session
220
223
  )
221
224
 
222
- op.execute(server, client: client, options: execution_opts)
225
+ op.execute(server,
226
+ context: Operation::Context.new(client: client, session: session),
227
+ options: execution_opts)
223
228
  end
224
229
  end
225
230
 
@@ -250,7 +255,7 @@ module Mongo
250
255
  :db_name => name,
251
256
  :read => preference,
252
257
  :session => session
253
- }).execute(server, client: client)
258
+ }).execute(server, context: Operation::Context.new(client: client, session: session))
254
259
  end
255
260
  end
256
261
  end
@@ -281,7 +286,7 @@ module Mongo
281
286
  db_name: name,
282
287
  write_concern: write_concern,
283
288
  session: session
284
- }).execute(next_primary(nil, session), client: client)
289
+ }).execute(next_primary(nil, session), context: Operation::Context.new(client: client, session: session))
285
290
  end
286
291
  end
287
292
 
@@ -321,8 +326,20 @@ module Mongo
321
326
 
322
327
  # Get the Grid "filesystem" for this database.
323
328
  #
324
- # @example Get the GridFS.
325
- # database.fs
329
+ # @param [ Hash ] options The GridFS options.
330
+ #
331
+ # @option options [ String ] :bucket_name The prefix for the files and chunks
332
+ # collections.
333
+ # @option options [ Integer ] :chunk_size Override the default chunk
334
+ # size.
335
+ # @option options [ String ] :fs_name The prefix for the files and chunks
336
+ # collections.
337
+ # @option options [ String ] :read The read preference.
338
+ # @option options [ Session ] :session The session to use.
339
+ # @option options [ Hash ] :write Deprecated. Equivalent to :write_concern
340
+ # option.
341
+ # @option options [ Hash ] :write_concern The write concern options.
342
+ # Can be :w => Integer|String, :fsync => Boolean, :j => Boolean.
326
343
  #
327
344
  # @return [ Grid::FSBucket ] The GridFS for the database.
328
345
  #
@@ -189,7 +189,7 @@ module Mongo
189
189
  end
190
190
 
191
191
  def send_initial_query(server, session, options = {})
192
- initial_query_op(session, options).execute(server, client: client)
192
+ initial_query_op(session, options).execute(server, context: Operation::Context.new(client: client, session: session))
193
193
  end
194
194
  end
195
195
  end
data/lib/mongo/error.rb CHANGED
@@ -29,16 +29,19 @@ module Mongo
29
29
  # An error field, MongoDB < 2.6
30
30
  #
31
31
  # @since 2.0.0
32
+ # @deprecated
32
33
  ERR = '$err'.freeze
33
34
 
34
35
  # An error field, MongoDB < 2.4
35
36
  #
36
37
  # @since 2.0.0
38
+ # @deprecated
37
39
  ERROR = 'err'.freeze
38
40
 
39
41
  # The standard error message field, MongoDB 3.0+
40
42
  #
41
43
  # @since 2.0.0
44
+ # @deprecated
42
45
  ERRMSG = 'errmsg'.freeze
43
46
 
44
47
  # The constant for the writeErrors array.
@@ -174,7 +177,7 @@ require 'mongo/error/credential_check_error'
174
177
  require 'mongo/error/crypt_error'
175
178
  require 'mongo/error/extra_file_chunk'
176
179
  require 'mongo/error/file_not_found'
177
- require 'mongo/error/operation_failure'
180
+ require 'mongo/error/handshake_error'
178
181
  require 'mongo/error/invalid_address'
179
182
  require 'mongo/error/invalid_bulk_operation'
180
183
  require 'mongo/error/invalid_bulk_operation_type'
@@ -202,6 +205,7 @@ require 'mongo/error/invalid_update_document'
202
205
  require 'mongo/error/invalid_uri'
203
206
  require 'mongo/error/invalid_write_concern'
204
207
  require 'mongo/error/insufficient_iteration_count'
208
+ require 'mongo/error/internal_driver_error'
205
209
  require 'mongo/error/kms_error'
206
210
  require 'mongo/error/lint_error'
207
211
  require 'mongo/error/max_bson_size'
@@ -214,6 +218,7 @@ require 'mongo/error/no_server_available'
214
218
  require 'mongo/error/no_srv_records'
215
219
  require 'mongo/error/session_ended'
216
220
  require 'mongo/error/sessions_not_supported'
221
+ require 'mongo/error/operation_failure'
217
222
  require 'mongo/error/pool_closed_error'
218
223
  require 'mongo/error/raise_original_error'
219
224
  require 'mongo/error/server_certificate_revoked'
@@ -227,7 +232,10 @@ require 'mongo/error/missing_file_chunk'
227
232
  require 'mongo/error/missing_password'
228
233
  require 'mongo/error/missing_resume_token'
229
234
  require 'mongo/error/missing_scram_server_signature'
235
+ require 'mongo/error/server_api_conflict'
236
+ require 'mongo/error/server_api_not_supported'
230
237
  require 'mongo/error/unknown_payload_type'
238
+ require 'mongo/error/unmet_dependency'
231
239
  require 'mongo/error/unsupported_option'
232
240
  require 'mongo/error/unsupported_array_filters'
233
241
  require 'mongo/error/unsupported_collation'