mongo 2.15.0 → 2.17.0

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 (393) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +1 -1
  4. data/lib/mongo/auth/aws/request.rb +0 -1
  5. data/lib/mongo/bulk_write.rb +2 -2
  6. data/lib/mongo/client.rb +49 -5
  7. data/lib/mongo/cluster/periodic_executor.rb +4 -3
  8. data/lib/mongo/cluster/reapers/cursor_reaper.rb +76 -43
  9. data/lib/mongo/cluster/sdam_flow.rb +9 -3
  10. data/lib/mongo/cluster/topology/base.rb +13 -9
  11. data/lib/mongo/cluster/topology/load_balanced.rb +102 -0
  12. data/lib/mongo/cluster/topology.rb +28 -8
  13. data/lib/mongo/cluster.rb +136 -51
  14. data/lib/mongo/collection/view/aggregation.rb +63 -23
  15. data/lib/mongo/collection/view/builder/aggregation.rb +16 -17
  16. data/lib/mongo/collection/view/builder/map_reduce.rb +12 -49
  17. data/lib/mongo/collection/view/builder.rb +0 -4
  18. data/lib/mongo/collection/view/change_stream.rb +7 -3
  19. data/lib/mongo/collection/view/iterable.rb +60 -27
  20. data/lib/mongo/collection/view/map_reduce.rb +41 -15
  21. data/lib/mongo/collection/view/readable.rb +84 -52
  22. data/lib/mongo/collection/view/writable.rb +201 -175
  23. data/lib/mongo/collection/view.rb +15 -21
  24. data/lib/mongo/collection.rb +34 -14
  25. data/lib/mongo/cursor/kill_spec.rb +38 -0
  26. data/lib/mongo/cursor.rb +72 -31
  27. data/lib/mongo/database/view.rb +5 -3
  28. data/lib/mongo/database.rb +6 -6
  29. data/lib/mongo/error/bad_load_balancer_target.rb +26 -0
  30. data/lib/mongo/error/missing_service_id.rb +26 -0
  31. data/lib/mongo/error/no_service_connection_available.rb +49 -0
  32. data/lib/mongo/error/notable.rb +7 -0
  33. data/lib/mongo/error/snapshot_session_invalid_server_version.rb +31 -0
  34. data/lib/mongo/error/snapshot_session_transaction_prohibited.rb +30 -0
  35. data/lib/mongo/error.rb +5 -0
  36. data/lib/mongo/grid/fs_bucket.rb +21 -2
  37. data/lib/mongo/id.rb +7 -5
  38. data/lib/mongo/index/view.rb +22 -41
  39. data/lib/mongo/monitoring/event/cmap/pool_cleared.rb +7 -4
  40. data/lib/mongo/monitoring/event/command_failed.rb +1 -1
  41. data/lib/mongo/monitoring/event/command_started.rb +2 -0
  42. data/lib/mongo/monitoring/publishable.rb +2 -2
  43. data/lib/mongo/operation/aggregate/command.rb +8 -0
  44. data/lib/mongo/operation/context.rb +19 -1
  45. data/lib/mongo/operation/count/command.rb +6 -0
  46. data/lib/mongo/operation/count/op_msg.rb +6 -0
  47. data/lib/mongo/operation/create/command.rb +7 -1
  48. data/lib/mongo/operation/create/op_msg.rb +7 -0
  49. data/lib/mongo/operation/create_index/command.rb +17 -1
  50. data/lib/mongo/operation/create_index/op_msg.rb +17 -4
  51. data/lib/mongo/operation/delete/command.rb +6 -3
  52. data/lib/mongo/operation/delete/legacy.rb +9 -2
  53. data/lib/mongo/operation/delete/op_msg.rb +9 -1
  54. data/lib/mongo/operation/distinct/command.rb +6 -0
  55. data/lib/mongo/operation/distinct/op_msg.rb +7 -0
  56. data/lib/mongo/operation/explain/command.rb +13 -1
  57. data/lib/mongo/operation/explain/legacy.rb +12 -5
  58. data/lib/mongo/operation/explain/op_msg.rb +9 -1
  59. data/lib/mongo/operation/find/builder/command.rb +111 -0
  60. data/lib/mongo/{collection/view → operation/find}/builder/flags.rb +10 -14
  61. data/lib/mongo/operation/find/builder/legacy.rb +123 -0
  62. data/lib/mongo/{collection/view → operation/find}/builder/modifiers.rb +31 -25
  63. data/lib/mongo/{cursor → operation/find}/builder.rb +4 -4
  64. data/lib/mongo/operation/find/command.rb +9 -0
  65. data/lib/mongo/operation/find/legacy.rb +10 -1
  66. data/lib/mongo/operation/find/op_msg.rb +12 -0
  67. data/lib/mongo/operation/find.rb +1 -0
  68. data/lib/mongo/operation/get_more/command.rb +1 -0
  69. data/lib/mongo/operation/get_more/command_builder.rb +38 -0
  70. data/lib/mongo/operation/get_more/op_msg.rb +1 -0
  71. data/lib/mongo/operation/get_more.rb +1 -0
  72. data/lib/mongo/operation/kill_cursors/command.rb +8 -0
  73. data/lib/mongo/operation/kill_cursors/command_builder.rb +35 -0
  74. data/lib/mongo/operation/kill_cursors/legacy.rb +2 -1
  75. data/lib/mongo/operation/kill_cursors/op_msg.rb +10 -0
  76. data/lib/mongo/operation/kill_cursors.rb +1 -0
  77. data/lib/mongo/operation/map_reduce/command.rb +8 -0
  78. data/lib/mongo/operation/map_reduce/op_msg.rb +1 -1
  79. data/lib/mongo/operation/result.rb +6 -0
  80. data/lib/mongo/operation/shared/executable.rb +19 -1
  81. data/lib/mongo/operation/shared/polymorphic_operation.rb +1 -1
  82. data/lib/mongo/operation/shared/read_preference_supported.rb +3 -1
  83. data/lib/mongo/operation/shared/response_handling.rb +1 -0
  84. data/lib/mongo/operation/shared/sessions_supported.rb +28 -12
  85. data/lib/mongo/operation/shared/specifiable.rb +11 -29
  86. data/lib/mongo/operation/shared/validatable.rb +87 -0
  87. data/lib/mongo/operation/shared/write.rb +1 -1
  88. data/lib/mongo/operation/update/command.rb +6 -3
  89. data/lib/mongo/operation/update/legacy.rb +19 -11
  90. data/lib/mongo/operation/update/op_msg.rb +8 -4
  91. data/lib/mongo/operation/write_command/command.rb +51 -0
  92. data/lib/mongo/operation/write_command/op_msg.rb +43 -0
  93. data/lib/mongo/operation/write_command.rb +32 -0
  94. data/lib/mongo/operation.rb +10 -0
  95. data/lib/mongo/protocol/query.rb +35 -18
  96. data/lib/mongo/server/connection.rb +25 -3
  97. data/lib/mongo/server/connection_base.rb +12 -1
  98. data/lib/mongo/server/connection_common.rb +38 -1
  99. data/lib/mongo/server/connection_pool/generation_manager.rb +71 -0
  100. data/lib/mongo/server/connection_pool.rb +100 -27
  101. data/lib/mongo/server/description/features.rb +20 -17
  102. data/lib/mongo/server/description/load_balancer.rb +33 -0
  103. data/lib/mongo/server/description.rb +85 -6
  104. data/lib/mongo/server/monitor/connection.rb +5 -6
  105. data/lib/mongo/server/monitor.rb +2 -1
  106. data/lib/mongo/server/pending_connection.rb +47 -31
  107. data/lib/mongo/server/push_monitor.rb +10 -1
  108. data/lib/mongo/server.rb +73 -26
  109. data/lib/mongo/server_selector/base.rb +31 -5
  110. data/lib/mongo/session/session_pool.rb +11 -0
  111. data/lib/mongo/session.rb +40 -1
  112. data/lib/mongo/socket/ocsp_cache.rb +2 -3
  113. data/lib/mongo/socket/ocsp_verifier.rb +6 -37
  114. data/lib/mongo/socket.rb +1 -5
  115. data/lib/mongo/uri/options_mapper.rb +1 -0
  116. data/lib/mongo/uri/srv_protocol.rb +6 -8
  117. data/lib/mongo/uri.rb +18 -0
  118. data/lib/mongo/utils.rb +0 -13
  119. data/lib/mongo/version.rb +1 -1
  120. data/mongo.gemspec +1 -1
  121. data/spec/integration/auth_spec.rb +31 -1
  122. data/spec/integration/awaited_ismaster_spec.rb +1 -1
  123. data/spec/integration/bulk_write_spec.rb +1 -1
  124. data/spec/integration/change_stream_spec.rb +3 -3
  125. data/spec/integration/client_construction_spec.rb +54 -0
  126. data/spec/integration/client_side_encryption/auto_encryption_bulk_writes_spec.rb +1 -1
  127. data/spec/integration/client_side_encryption/auto_encryption_command_monitoring_spec.rb +1 -1
  128. data/spec/integration/client_side_encryption/bson_size_limit_spec.rb +1 -1
  129. data/spec/integration/client_side_encryption/data_key_spec.rb +1 -1
  130. data/spec/integration/client_spec.rb +2 -0
  131. data/spec/integration/command_monitoring_spec.rb +1 -1
  132. data/spec/integration/command_spec.rb +1 -1
  133. data/spec/integration/connection_spec.rb +52 -35
  134. data/spec/integration/crud_spec.rb +174 -1
  135. data/spec/integration/cursor_pinning_spec.rb +121 -0
  136. data/spec/integration/cursor_reaping_spec.rb +8 -4
  137. data/spec/integration/fork_reconnect_spec.rb +1 -5
  138. data/spec/integration/get_more_spec.rb +1 -1
  139. data/spec/integration/heartbeat_events_spec.rb +1 -1
  140. data/spec/integration/map_reduce_spec.rb +77 -0
  141. data/spec/integration/query_cache_spec.rb +47 -2
  142. data/spec/integration/query_cache_transactions_spec.rb +1 -1
  143. data/spec/integration/read_concern_spec.rb +1 -1
  144. data/spec/integration/read_preference_spec.rb +17 -13
  145. data/spec/integration/reconnect_spec.rb +30 -12
  146. data/spec/integration/retryable_errors_spec.rb +1 -1
  147. data/spec/integration/retryable_writes/retryable_writes_36_and_older_spec.rb +1 -1
  148. data/spec/integration/retryable_writes/retryable_writes_40_and_newer_spec.rb +1 -1
  149. data/spec/integration/sdam_error_handling_spec.rb +5 -3
  150. data/spec/integration/sdam_events_spec.rb +35 -19
  151. data/spec/integration/sdam_prose_spec.rb +1 -1
  152. data/spec/integration/server_monitor_spec.rb +1 -0
  153. data/spec/integration/server_selector_spec.rb +22 -5
  154. data/spec/integration/server_spec.rb +2 -0
  155. data/spec/integration/srv_monitoring_spec.rb +1 -1
  156. data/spec/integration/step_down_spec.rb +1 -1
  157. data/spec/integration/transaction_pinning_spec.rb +120 -0
  158. data/spec/integration/versioned_api_examples_spec.rb +45 -0
  159. data/spec/integration/x509_auth_spec.rb +1 -1
  160. data/spec/lite_spec_helper.rb +1 -2
  161. data/spec/mongo/address/unix_spec.rb +1 -0
  162. data/spec/mongo/auth/cr_spec.rb +2 -3
  163. data/spec/mongo/auth/ldap_spec.rb +2 -3
  164. data/spec/mongo/auth/scram_spec.rb +2 -3
  165. data/spec/mongo/auth/user/view_spec.rb +1 -1
  166. data/spec/mongo/auth/x509_spec.rb +2 -3
  167. data/spec/mongo/bulk_write_spec.rb +3 -3
  168. data/spec/mongo/client_construction_spec.rb +259 -28
  169. data/spec/mongo/client_spec.rb +6 -4
  170. data/spec/mongo/cluster/cursor_reaper_spec.rb +36 -21
  171. data/spec/mongo/cluster/periodic_executor_spec.rb +3 -1
  172. data/spec/mongo/cluster_spec.rb +44 -3
  173. data/spec/mongo/collection/view/aggregation_spec.rb +72 -96
  174. data/spec/mongo/collection/view/builder/find_command_spec.rb +4 -0
  175. data/spec/mongo/collection/view/builder/op_query_spec.rb +4 -0
  176. data/spec/mongo/collection/view/change_stream_spec.rb +1 -1
  177. data/spec/mongo/collection/view/map_reduce_spec.rb +15 -2
  178. data/spec/mongo/collection_crud_spec.rb +7 -2
  179. data/spec/mongo/collection_ddl_spec.rb +1 -1
  180. data/spec/mongo/collection_spec.rb +1 -1
  181. data/spec/mongo/cursor/builder/get_more_command_spec.rb +4 -0
  182. data/spec/mongo/cursor/builder/op_get_more_spec.rb +4 -0
  183. data/spec/mongo/cursor_spec.rb +15 -5
  184. data/spec/mongo/database_spec.rb +15 -15
  185. data/spec/mongo/error/operation_failure_heavy_spec.rb +1 -1
  186. data/spec/mongo/grid/fs_bucket_spec.rb +18 -12
  187. data/spec/mongo/grid/stream/write_spec.rb +3 -9
  188. data/spec/mongo/grid/stream_spec.rb +1 -1
  189. data/spec/mongo/index/view_spec.rb +2 -2
  190. data/spec/mongo/operation/delete/op_msg_spec.rb +1 -1
  191. data/spec/mongo/{collection/view → operation/find}/builder/flags_spec.rb +2 -2
  192. data/spec/mongo/{collection/view → operation/find}/builder/modifiers_spec.rb +2 -2
  193. data/spec/mongo/operation/find/legacy_spec.rb +1 -0
  194. data/spec/mongo/operation/insert/bulk_spec.rb +1 -1
  195. data/spec/mongo/operation/insert/op_msg_spec.rb +1 -1
  196. data/spec/mongo/operation/kill_cursors_spec.rb +4 -1
  197. data/spec/mongo/operation/read_preference_legacy_spec.rb +4 -0
  198. data/spec/mongo/operation/read_preference_op_msg_spec.rb +26 -1
  199. data/spec/mongo/operation/update/bulk_spec.rb +1 -1
  200. data/spec/mongo/operation/update/op_msg_spec.rb +1 -1
  201. data/spec/mongo/query_cache_spec.rb +6 -2
  202. data/spec/mongo/server/connection_common_spec.rb +62 -11
  203. data/spec/mongo/server/connection_pool_spec.rb +73 -7
  204. data/spec/mongo/server/connection_spec.rb +138 -43
  205. data/spec/mongo/server/description_spec.rb +1 -1
  206. data/spec/mongo/server/monitor/connection_spec.rb +22 -0
  207. data/spec/mongo/server/monitor_spec.rb +4 -3
  208. data/spec/mongo/server/push_monitor_spec.rb +101 -0
  209. data/spec/mongo/server_selector_spec.rb +136 -15
  210. data/spec/mongo/session/session_pool_spec.rb +42 -10
  211. data/spec/mongo/session_transaction_spec.rb +15 -30
  212. data/spec/mongo/socket/ssl_spec.rb +26 -58
  213. data/spec/mongo/socket/unix_spec.rb +1 -0
  214. data/spec/mongo/uri_option_parsing_spec.rb +38 -5
  215. data/spec/mongo/utils_spec.rb +0 -14
  216. data/spec/runners/change_streams/test.rb +1 -1
  217. data/spec/runners/cmap.rb +1 -1
  218. data/spec/runners/connection_string.rb +7 -3
  219. data/spec/runners/crud/operation.rb +5 -3
  220. data/spec/runners/crud/requirement.rb +1 -0
  221. data/spec/runners/crud/verifier.rb +1 -2
  222. data/spec/runners/crud.rb +1 -1
  223. data/spec/runners/sdam.rb +2 -1
  224. data/spec/runners/transactions/test.rb +2 -2
  225. data/spec/runners/unified/assertions.rb +5 -4
  226. data/spec/runners/unified/crud_operations.rb +77 -23
  227. data/spec/runners/unified/ddl_operations.rb +29 -1
  228. data/spec/runners/unified/entity_map.rb +3 -3
  229. data/spec/runners/unified/event_subscriber.rb +2 -2
  230. data/spec/runners/unified/support_operations.rb +16 -3
  231. data/spec/runners/unified/test.rb +18 -3
  232. data/spec/runners/unified.rb +1 -1
  233. data/spec/shared/lib/mrss/cluster_config.rb +6 -1
  234. data/spec/shared/lib/mrss/constraints.rb +11 -5
  235. data/spec/shared/lib/mrss/event_subscriber.rb +200 -0
  236. data/spec/shared/lib/mrss/server_version_registry.rb +17 -12
  237. data/spec/shared/share/Dockerfile.erb +5 -4
  238. data/spec/shared/shlib/server.sh +70 -20
  239. data/spec/spec_tests/change_streams_spec.rb +1 -1
  240. data/spec/spec_tests/cmap_spec.rb +4 -1
  241. data/spec/spec_tests/command_monitoring_spec.rb +2 -2
  242. data/spec/spec_tests/data/command_monitoring/find.yml +9 -9
  243. data/spec/spec_tests/data/crud/read/aggregate-collation.yml +2 -1
  244. data/spec/spec_tests/data/crud/read/aggregate-out.yml +1 -0
  245. data/spec/spec_tests/data/crud/read/count-collation.yml +2 -1
  246. data/spec/spec_tests/data/crud/read/distinct-collation.yml +2 -1
  247. data/spec/spec_tests/data/crud/read/find-collation.yml +2 -1
  248. data/spec/spec_tests/data/crud/write/bulkWrite-collation.yml +2 -1
  249. data/spec/spec_tests/data/crud/write/deleteMany-collation.yml +2 -1
  250. data/spec/spec_tests/data/crud/write/deleteOne-collation.yml +2 -1
  251. data/spec/spec_tests/data/crud/write/findOneAndDelete-collation.yml +3 -2
  252. data/spec/spec_tests/data/crud/write/findOneAndReplace-collation.yml +2 -1
  253. data/spec/spec_tests/data/crud/write/findOneAndUpdate-collation.yml +3 -2
  254. data/spec/spec_tests/data/crud/write/replaceOne-collation.yml +3 -2
  255. data/spec/spec_tests/data/crud/write/updateMany-collation.yml +2 -1
  256. data/spec/spec_tests/data/crud/write/updateOne-collation.yml +2 -1
  257. data/spec/spec_tests/data/crud_unified/aggregate-let.yml +138 -0
  258. data/spec/spec_tests/data/crud_unified/aggregate-write-readPreference.yml +155 -0
  259. data/spec/spec_tests/data/crud_unified/db-aggregate-write-readPreference.yml +151 -0
  260. data/spec/spec_tests/data/crud_unified/deleteMany-let.yml +91 -0
  261. data/spec/spec_tests/data/crud_unified/deleteOne-let.yml +89 -0
  262. data/spec/spec_tests/data/crud_unified/find-let.yml +71 -0
  263. data/spec/spec_tests/data/crud_unified/findOneAndDelete-let.yml +88 -0
  264. data/spec/spec_tests/data/crud_unified/findOneAndReplace-let.yml +94 -0
  265. data/spec/spec_tests/data/crud_unified/findOneAndUpdate-let.yml +96 -0
  266. data/spec/spec_tests/data/crud_unified/updateMany-let.yml +103 -0
  267. data/spec/spec_tests/data/crud_unified/updateOne-let.yml +98 -0
  268. data/spec/spec_tests/data/load_balancers/event-monitoring.yml +99 -0
  269. data/spec/spec_tests/data/load_balancers/lb-connection-establishment.yml +36 -0
  270. data/spec/spec_tests/data/load_balancers/non-lb-connection-establishment.yml +56 -0
  271. data/spec/spec_tests/data/load_balancers/server-selection.yml +50 -0
  272. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/DefaultNoMaxStaleness.yml +2 -2
  273. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.yml +3 -3
  274. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/Nearest.yml +3 -3
  275. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/Nearest2.yml +3 -3
  276. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.yml +2 -2
  277. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.yml +2 -2
  278. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/Secondary.yml +4 -4
  279. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.yml +2 -2
  280. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.yml +4 -4
  281. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/ZeroMaxStaleness.yml +2 -2
  282. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/DefaultNoMaxStaleness.yml +2 -2
  283. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.yml +3 -3
  284. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/LongHeartbeat.yml +2 -2
  285. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/LongHeartbeat2.yml +2 -2
  286. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.yml +2 -2
  287. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.yml +2 -2
  288. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/Nearest.yml +3 -3
  289. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/Nearest2.yml +3 -3
  290. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/Nearest_tags.yml +2 -2
  291. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.yml +2 -2
  292. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.yml +2 -2
  293. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.yml +5 -5
  294. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.yml +3 -3
  295. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/Secondary_tags.yml +5 -5
  296. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.yml +3 -3
  297. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.yml +2 -2
  298. data/spec/spec_tests/data/max_staleness/Sharded/SmallMaxStaleness.yml +2 -2
  299. data/spec/spec_tests/data/max_staleness/Single/SmallMaxStaleness.yml +1 -1
  300. data/spec/spec_tests/data/max_staleness/Unknown/SmallMaxStaleness.yml +1 -1
  301. data/spec/spec_tests/data/retryable_reads/changeStreams-client.watch-serverErrors.yml +1 -1
  302. data/spec/spec_tests/data/retryable_reads/changeStreams-client.watch.yml +1 -1
  303. data/spec/spec_tests/data/retryable_reads/changeStreams-db.coll.watch-serverErrors.yml +1 -1
  304. data/spec/spec_tests/data/retryable_reads/changeStreams-db.coll.watch.yml +1 -1
  305. data/spec/spec_tests/data/retryable_reads/changeStreams-db.watch-serverErrors.yml +1 -1
  306. data/spec/spec_tests/data/retryable_reads/changeStreams-db.watch.yml +1 -1
  307. data/spec/spec_tests/data/retryable_reads/mapReduce.yml +3 -1
  308. data/spec/spec_tests/data/sdam/load-balanced/discover_load_balancer.yml +25 -0
  309. data/spec/spec_tests/data/sdam_integration/find-network-error.yml +2 -0
  310. data/spec/spec_tests/data/sdam_integration/find-shutdown-error.yml +2 -0
  311. data/spec/spec_tests/data/sdam_integration/hello-command-error.yml +3 -1
  312. data/spec/spec_tests/data/sdam_integration/hello-network-error.yml +3 -1
  313. data/spec/spec_tests/data/sdam_integration/hello-timeout.yml +2 -0
  314. data/spec/spec_tests/data/sdam_integration/insert-network-error.yml +2 -0
  315. data/spec/spec_tests/data/sdam_integration/insert-shutdown-error.yml +2 -0
  316. data/spec/spec_tests/data/sdam_monitoring/load_balancer.yml +65 -0
  317. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-directConnection.yml +13 -0
  318. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-replicaSet-errors.yml +6 -0
  319. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-true-multiple-hosts.yml +5 -0
  320. data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-true-txt.yml +10 -0
  321. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/direct-connection-false.yml +0 -0
  322. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/direct-connection-true.yml +0 -0
  323. data/spec/spec_tests/data/seed_list_discovery/replica-set/encoded-userinfo-and-db.yml +15 -0
  324. data/spec/spec_tests/data/seed_list_discovery/replica-set/loadBalanced-false-txt.yml +10 -0
  325. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/longer-parent-in-return.yml +0 -0
  326. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/misformatted-option.yml +0 -0
  327. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/no-results.yml +0 -0
  328. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/not-enough-parts.yml +0 -0
  329. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/one-result-default-port.yml +0 -0
  330. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/one-txt-record-multiple-strings.yml +0 -0
  331. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/one-txt-record.yml +0 -0
  332. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch1.yml +0 -0
  333. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch2.yml +0 -0
  334. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch3.yml +0 -0
  335. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch4.yml +0 -0
  336. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch5.yml +0 -0
  337. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/returned-parent-too-short.yml +0 -0
  338. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/returned-parent-wrong.yml +0 -0
  339. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/two-results-default-port.yml +0 -0
  340. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/two-results-nonstandard-port.yml +0 -0
  341. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/two-txt-records.yml +0 -0
  342. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-not-allowed-option.yml +0 -0
  343. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-with-overridden-ssl-option.yml +0 -0
  344. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-with-overridden-uri-option.yml +0 -0
  345. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-with-unallowed-option.yml +0 -0
  346. data/spec/spec_tests/data/seed_list_discovery/replica-set/uri-with-admin-database.yml +13 -0
  347. data/spec/spec_tests/data/seed_list_discovery/replica-set/uri-with-auth.yml +12 -0
  348. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/uri-with-port.yml +0 -0
  349. data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/uri-with-two-hosts.yml +0 -0
  350. data/spec/spec_tests/data/sessions_unified/snapshot-sessions-not-supported-client-error.yml +69 -0
  351. data/spec/spec_tests/data/sessions_unified/snapshot-sessions-not-supported-server-error.yml +102 -0
  352. data/spec/spec_tests/data/sessions_unified/snapshot-sessions-unsupported-ops.yml +258 -0
  353. data/spec/spec_tests/data/sessions_unified/snapshot-sessions.yml +482 -0
  354. data/spec/spec_tests/data/transactions/retryable-abort-errorLabels.yml +2 -0
  355. data/spec/spec_tests/data/transactions/retryable-abort.yml +2 -0
  356. data/spec/spec_tests/data/transactions/retryable-commit-errorLabels.yml +2 -0
  357. data/spec/spec_tests/data/transactions/retryable-commit.yml +2 -0
  358. data/spec/spec_tests/data/transactions/retryable-writes.yml +2 -0
  359. data/spec/spec_tests/data/uri_options/connection-options.yml +60 -0
  360. data/spec/spec_tests/load_balancers_spec.rb +15 -0
  361. data/spec/spec_tests/retryable_reads_spec.rb +2 -2
  362. data/spec/spec_tests/retryable_writes_spec.rb +1 -1
  363. data/spec/spec_tests/sdam_integration_spec.rb +1 -1
  364. data/spec/spec_tests/sdam_monitoring_spec.rb +10 -5
  365. data/spec/spec_tests/sdam_spec.rb +1 -1
  366. data/spec/spec_tests/seed_list_discovery_spec.rb +118 -0
  367. data/spec/spec_tests/sessions_unified_spec.rb +13 -0
  368. data/spec/spec_tests/uri_options_spec.rb +4 -4
  369. data/spec/stress/fork_reconnect_stress_spec.rb +1 -5
  370. data/spec/stress/push_monitor_close_spec.rb +44 -0
  371. data/spec/support/certificates/atlas-ocsp-ca.crt +82 -90
  372. data/spec/support/certificates/atlas-ocsp.crt +127 -122
  373. data/spec/support/common_shortcuts.rb +2 -3
  374. data/spec/support/matchers.rb +13 -0
  375. data/spec/support/shared/auth_context.rb +16 -0
  376. data/spec/support/shared/session.rb +2 -2
  377. data/spec/support/spec_config.rb +10 -11
  378. data/spec/support/using_hash.rb +31 -0
  379. data/spec/support/utils.rb +1 -1
  380. data.tar.gz.sig +3 -4
  381. metadata +1111 -1029
  382. metadata.gz.sig +2 -3
  383. data/lib/mongo/collection/view/builder/find_command.rb +0 -173
  384. data/lib/mongo/collection/view/builder/op_query.rb +0 -94
  385. data/lib/mongo/cursor/builder/get_more_command.rb +0 -80
  386. data/lib/mongo/cursor/builder/kill_cursors_command.rb +0 -111
  387. data/lib/mongo/cursor/builder/op_get_more.rb +0 -64
  388. data/lib/mongo/cursor/builder/op_kill_cursors.rb +0 -106
  389. data/lib/mongo/server/context.rb +0 -72
  390. data/spec/mongo/cursor/builder/op_kill_cursors_spec.rb +0 -66
  391. data/spec/runners/unified/using_hash.rb +0 -34
  392. data/spec/spec_tests/dns_seedlist_discovery_spec.rb +0 -79
  393. data/spec/support/event_subscriber.rb +0 -221
@@ -25,6 +25,13 @@ module Mongo
25
25
  # @since 2.0.0
26
26
  module Iterable
27
27
 
28
+ # Returns the cursor associated with this view, if any.
29
+ #
30
+ # @return [ nil | Cursor ] The cursor, if any.
31
+ #
32
+ # @api private
33
+ attr_reader :cursor
34
+
28
35
  # Iterate through documents returned by a query with this +View+.
29
36
  #
30
37
  # @example Iterate through the result of the view.
@@ -38,18 +45,28 @@ module Mongo
38
45
  #
39
46
  # @yieldparam [ Hash ] Each matching document.
40
47
  def each
41
- @cursor = if use_query_cache? && cached_cursor
48
+ # If the caching cursor is closed and was not fully iterated,
49
+ # the documents we have in it are not the complete result set and
50
+ # we have no way of completing that iteration.
51
+ # Therefore, discard that cursor and start iteration again.
52
+ # The case of the caching cursor not being closed and not having
53
+ # been fully iterated isn't tested - see RUBY-2773.
54
+ @cursor = if use_query_cache? && cached_cursor && (
55
+ cached_cursor.fully_iterated? || !cached_cursor.closed?
56
+ )
42
57
  cached_cursor
43
58
  else
44
59
  session = client.send(:get_session, @options)
45
- select_cursor(session)
60
+ select_cursor(session).tap do |cursor|
61
+ if use_query_cache?
62
+ # No need to store the cursor in the query cache if there is
63
+ # already a cached cursor stored at this key.
64
+ QueryCache.set(cursor, **cache_options)
65
+ end
66
+ end
46
67
  end
47
68
 
48
69
  if use_query_cache?
49
- # No need to store the cursor in the query cache if there is
50
- # already a cached cursor stored at this key.
51
- QueryCache.set(@cursor, **cache_options) unless cached_cursor
52
-
53
70
  # If a query with a limit is performed, the query cache will
54
71
  # re-use results from an earlier query with the same or larger
55
72
  # limit, and then impose the lower limit during iteration.
@@ -97,11 +114,9 @@ module Mongo
97
114
 
98
115
  def select_cursor(session)
99
116
  if respond_to?(:write?, true) && write?
100
- server = server_selector.select_server(cluster, nil, session)
117
+ server = server_selector.select_server(cluster, nil, session, write_aggregation: true)
101
118
  result = send_initial_query(server, session)
102
119
 
103
- # RUBY-2367: This will be updated to allow the query cache to
104
- # cache cursors with multi-batch results.
105
120
  if use_query_cache?
106
121
  CachingCursor.new(view, result, server, session: session)
107
122
  else
@@ -130,36 +145,54 @@ module Mongo
130
145
  projection: projection,
131
146
  collation: collation,
132
147
  read_concern: read_concern,
133
- read_preference: read_preference
134
-
148
+ read_preference: read_preference,
135
149
  }
136
150
  end
137
151
 
138
152
  def initial_query_op(server, session)
139
- if server.with_connection { |connection| connection.features }.find_command_enabled?
140
- initial_command_op(session)
141
- else
142
- # Server versions that do not have the find command feature
143
- # (versions older than 3.2) do not support the allow_disk_use option
144
- # but perform no validation and will not raise an error if it is
145
- # specified. If the allow_disk_use option is specified, raise an error
146
- # to alert the user.
147
- raise Error::UnsupportedOption.allow_disk_use_error if options.key?(:allow_disk_use)
148
- Operation::Find.new(Builder::OpQuery.new(self).specification)
153
+ spec = {
154
+ coll_name: collection.name,
155
+ filter: filter,
156
+ projection: projection,
157
+ db_name: database.name,
158
+ session: session,
159
+ collation: collation,
160
+ sort: sort,
161
+ skip: skip,
162
+ let: options[:let],
163
+ limit: limit,
164
+ allow_disk_use: options[:allow_disk_use],
165
+ read: read,
166
+ read_concern: options[:read_concern] || read_concern,
167
+ batch_size: batch_size,
168
+ hint: options[:hint],
169
+ max_scan: options[:max_scan],
170
+ max_time_ms: options[:max_time_ms],
171
+ max_value: options[:max_value],
172
+ min_value: options[:min_value],
173
+ return_key: options[:return_key],
174
+ show_disk_loc: options[:show_disk_loc],
175
+ comment: options[:comment],
176
+ oplog_replay: if (v = options[:oplog_replay]).nil?
177
+ collection.options[:oplog_replay]
178
+ else
179
+ v
180
+ end,
181
+ }
182
+
183
+ if spec[:oplog_replay]
184
+ collection.client.log_warn("The :oplog_replay option is deprecated and ignored by MongoDB 4.4 and later")
149
185
  end
150
- end
151
186
 
152
- def initial_command_op(session)
153
- builder = Builder::FindCommand.new(self, session)
154
187
  if explained?
155
- Operation::Explain.new(builder.explain_specification)
188
+ spec[:explain] = options[:explain]
189
+ Operation::Explain.new(spec)
156
190
  else
157
- Operation::Find.new(builder.specification)
191
+ Operation::Find.new(spec)
158
192
  end
159
193
  end
160
194
 
161
195
  def send_initial_query(server, session = nil)
162
- validate_collation!(server, collation)
163
196
  initial_query_op(server, session).execute(server, context: Operation::Context.new(client: client, session: session))
164
197
  end
165
198
 
@@ -115,6 +115,8 @@ module Mongo
115
115
  @map_function = map.dup.freeze
116
116
  @reduce_function = reduce.dup.freeze
117
117
  @options = BSON::Document.new(options).freeze
118
+
119
+ client.log_warn('The map_reduce operation is deprecated, please use the aggregation pipeline instead')
118
120
  end
119
121
 
120
122
  # Set or get the jsMode flag for the operation.
@@ -156,6 +158,28 @@ module Mongo
156
158
  configure(:out, location)
157
159
  end
158
160
 
161
+ # Returns the collection name where the map-reduce result is written to.
162
+ # If the result is returned inline, returns nil.
163
+ def out_collection_name
164
+ if options[:out].respond_to?(:keys)
165
+ options[:out][OUT_ACTIONS.find do |action|
166
+ options[:out][action]
167
+ end]
168
+ end || options[:out]
169
+ end
170
+
171
+ # Returns the database name where the map-reduce result is written to.
172
+ # If the result is returned inline, returns nil.
173
+ def out_database_name
174
+ if options[:out]
175
+ if options[:out].respond_to?(:keys) && (db = options[:out][:db])
176
+ db
177
+ else
178
+ database.name
179
+ end
180
+ end
181
+ end
182
+
159
183
  # Set or get a scope on the operation.
160
184
  #
161
185
  # @example Set the scope value.
@@ -207,6 +231,8 @@ module Mongo
207
231
 
208
232
  private
209
233
 
234
+ OUT_ACTIONS = [ :replace, :merge, :reduce ].freeze
235
+
210
236
  def server_selector
211
237
  @view.send(:server_selector)
212
238
  end
@@ -228,10 +254,12 @@ module Mongo
228
254
  end
229
255
 
230
256
  def valid_server?(server)
231
- description = server.with_connection do |connection|
232
- connection.description
257
+ if secondary_ok?
258
+ true
259
+ else
260
+ description = server.description
261
+ description.standalone? || description.mongos? || description.primary? || description.load_balancer?
233
262
  end
234
- description.standalone? || description.mongos? || description.primary? || secondary_ok?
235
263
  end
236
264
 
237
265
  def secondary_ok?
@@ -244,7 +272,6 @@ module Mongo
244
272
  log_warn(msg)
245
273
  server = cluster.next_primary(nil, session)
246
274
  end
247
- validate_collation!(server)
248
275
  initial_query_op(session).execute(server, context: Operation::Context.new(client: client, session: session))
249
276
  end
250
277
 
@@ -257,22 +284,21 @@ module Mongo
257
284
  end
258
285
 
259
286
  def fetch_query_op(server, session)
260
- if server.with_connection { |connection| connection.features }.find_command_enabled?
261
- Operation::Find.new(find_command_spec(session))
262
- else
263
- Operation::Find.new(fetch_query_spec)
264
- end
287
+ spec = {
288
+ coll_name: out_collection_name,
289
+ db_name: out_database_name,
290
+ filter: {},
291
+ session: session,
292
+ read: read,
293
+ read_concern: options[:read_concern] || collection.read_concern,
294
+ collation: options[:collation] || view.options[:collation],
295
+ }
296
+ Operation::Find.new(spec)
265
297
  end
266
298
 
267
299
  def send_fetch_query(server, session)
268
300
  fetch_query_op(server, session).execute(server, context: Operation::Context.new(client: client, session: session))
269
301
  end
270
-
271
- def validate_collation!(server)
272
- if (view.options[:collation] || options[:collation]) && !server.with_connection { |connection| connection.features }.collation_enabled?
273
- raise Error::UnsupportedCollation.new
274
- end
275
- end
276
302
  end
277
303
  end
278
304
  end
@@ -24,16 +24,6 @@ module Mongo
24
24
  # @since 2.0.0
25
25
  module Readable
26
26
 
27
- # The query modifier constant.
28
- #
29
- # @since 2.2.0
30
- QUERY = '$query'.freeze
31
-
32
- # The modifiers option constant.
33
- #
34
- # @since 2.2.0
35
- MODIFIERS = 'modifiers'.freeze
36
-
37
27
  # Execute an aggregation on the collection view.
38
28
  #
39
29
  # @example Aggregate documents.
@@ -44,6 +34,25 @@ module Mongo
44
34
  # @param [ Array<Hash> ] pipeline The aggregation pipeline.
45
35
  # @param [ Hash ] options The aggregation options.
46
36
  #
37
+ # @option options [ true, false ] :allow_disk_use Set to true if disk
38
+ # usage is allowed during the aggregation.
39
+ # @option options [ Integer ] :batch_size The number of documents to return
40
+ # per batch.
41
+ # @option options [ true, false ] :bypass_document_validation Whether or
42
+ # not to skip document level validation.
43
+ # @option options [ Hash ] :collation The collation to use.
44
+ # @option options [ String ] :comment Associate a comment with the aggregation.
45
+ # @option options [ String ] :hint The index to use for the aggregation.
46
+ # @option options [ Hash ] :let Mapping of variables to use in the pipeline.
47
+ # See the server documentation for details.
48
+ # @option options [ Integer ] :max_time_ms The maximum amount of time in
49
+ # milliseconds to allow the aggregation to run.
50
+ # @option options [ true, false ] :use_cursor Indicates whether the command
51
+ # will request that the server provide results using a cursor. Note that
52
+ # as of server version 3.6, aggregations always provide results using a
53
+ # cursor and this option is therefore not valid.
54
+ # @option options [ Session ] :session The session to use.
55
+ #
47
56
  # @return [ Aggregation ] The aggregation object.
48
57
  #
49
58
  # @since 2.0.0
@@ -169,13 +178,15 @@ module Mongo
169
178
  selector = ServerSelector.get(read_pref || server_selector)
170
179
  with_session(opts) do |session|
171
180
  read_with_retry(session, selector) do |server|
172
- apply_collation!(cmd, server, opts)
173
181
  Operation::Count.new(
174
- :selector => cmd,
175
- :db_name => database.name,
176
- :options => {:limit => -1},
177
- :read => read_pref,
178
- :session => session,
182
+ selector: cmd,
183
+ db_name: database.name,
184
+ options: {:limit => -1},
185
+ read: read_pref,
186
+ session: session,
187
+ # For some reason collation was historically accepted as a
188
+ # string key. Note that this isn't documented as valid usage.
189
+ collation: opts[:collation] || opts['collation'] || collation,
179
190
  ).execute(server, context: Operation::Context.new(client: client, session: session))
180
191
  end.n.to_i
181
192
  end
@@ -243,14 +254,18 @@ module Mongo
243
254
  read_pref = opts[:read] || read_preference
244
255
  selector = ServerSelector.get(read_pref || server_selector)
245
256
  with_session(opts) do |session|
246
- context = Operation::Context.new(client: client, session: session)
247
257
  read_with_retry(session, selector) do |server|
258
+ context = Operation::Context.new(client: client, session: session)
248
259
  if server.description.server_version_gte?('5.0')
249
260
  pipeline = [
250
261
  {'$collStats' => {'count' => {}}},
251
262
  {'$group' => {'_id' => 1, 'n' => {'$sum' => '$count'}}},
252
263
  ]
253
- spec = Builder::Aggregation.new(pipeline, self, options.merge(session: session)).specification
264
+ spec = Builder::Aggregation.new(
265
+ pipeline,
266
+ self,
267
+ options.merge(session: session)
268
+ ).specification
254
269
  result = Operation::Aggregate.new(spec).execute(server, context: context)
255
270
  result.documents.first.fetch('n')
256
271
  else
@@ -315,14 +330,16 @@ module Mongo
315
330
  selector = ServerSelector.get(read_pref || server_selector)
316
331
  with_session(opts) do |session|
317
332
  read_with_retry(session, selector) do |server|
318
- apply_collation!(cmd, server, opts)
319
- Operation::Distinct.new({
320
- :selector => cmd,
321
- :db_name => database.name,
322
- :options => {:limit => -1},
323
- :read => read_pref,
324
- :session => session,
325
- }).execute(server, context: Operation::Context.new(client: client, session: session))
333
+ Operation::Distinct.new(
334
+ selector: cmd,
335
+ db_name: database.name,
336
+ options: {:limit => -1},
337
+ read: read_pref,
338
+ session: session,
339
+ # For some reason collation was historically accepted as a
340
+ # string key. Note that this isn't documented as valid usage.
341
+ collation: opts[:collation] || opts['collation'] || collation,
342
+ ).execute(server, context: Operation::Context.new(client: client, session: session))
326
343
  end.first['values']
327
344
  end
328
345
  end
@@ -542,7 +559,11 @@ module Mongo
542
559
  configure(:sort, spec)
543
560
  end
544
561
 
545
- # “meta” operators that let you modify the output or behavior of a query.
562
+ # If called without arguments or with a nil argument, returns
563
+ # the legacy (OP_QUERY) server modifiers for the current view.
564
+ # If called with a non-nil argument, which must be a Hash or a
565
+ # subclass, merges the provided modifiers into the current view.
566
+ # Both string and symbol keys are allowed in the input hash.
546
567
  #
547
568
  # @example Set the modifiers document.
548
569
  # view.modifiers(:$orderby => Mongo::Index::ASCENDING)
@@ -553,8 +574,11 @@ module Mongo
553
574
  #
554
575
  # @since 2.1.0
555
576
  def modifiers(doc = nil)
556
- return Builder::Modifiers.map_server_modifiers(options) if doc.nil?
557
- new(options.merge(Builder::Modifiers.map_driver_options(doc)))
577
+ if doc.nil?
578
+ Operation::Find::Builder::Modifiers.map_server_modifiers(options)
579
+ else
580
+ new(options.merge(Operation::Find::Builder::Modifiers.map_driver_options(BSON::Document.new(doc))))
581
+ end
558
582
  end
559
583
 
560
584
  # A cumulative time limit in milliseconds for processing get more operations
@@ -645,34 +669,42 @@ module Mongo
645
669
 
646
670
  def parallel_scan(cursor_count, options = {})
647
671
  if options[:session]
672
+ # The session would be overwritten by the one in +options+ later.
648
673
  session = client.send(:get_session, @options)
649
674
  else
650
675
  session = nil
651
676
  end
652
677
  server = server_selector.select_server(cluster, nil, session)
653
- cmd = Operation::ParallelScan.new({
654
- :coll_name => collection.name,
655
- :db_name => database.name,
656
- :cursor_count => cursor_count,
657
- :read_concern => read_concern,
658
- :session => session,
659
- }.merge!(options))
660
- cmd.execute(server, context: Operation::Context.new(client: client, session: session)).cursor_ids.map do |cursor_id|
661
- result = if server.with_connection { |connection| connection.features }.find_command_enabled?
662
- Operation::GetMore.new({
663
- :selector => {:getMore => BSON::Int64.new(cursor_id),
664
- :collection => collection.name},
665
- :db_name => database.name,
666
- :session => session,
667
- }).execute(server, context: Operation::Context.new(client: client, session: session))
668
- else
669
- Operation::GetMore.new({
670
- :to_return => 0,
671
- :cursor_id => BSON::Int64.new(cursor_id),
672
- :db_name => database.name,
673
- :coll_name => collection.name
674
- }).execute(server, context: Operation::Context.new(client: client, session: session))
675
- end
678
+ spec = {
679
+ coll_name: collection.name,
680
+ db_name: database.name,
681
+ cursor_count: cursor_count,
682
+ read_concern: read_concern,
683
+ session: session,
684
+ }.update(options)
685
+ session = spec[:session]
686
+ op = Operation::ParallelScan.new(spec)
687
+ # Note that the context object shouldn't be reused for subsequent
688
+ # GetMore operations.
689
+ context = Operation::Context.new(client: client, session: session)
690
+ result = op.execute(server, context: context)
691
+ result.cursor_ids.map do |cursor_id|
692
+ spec = {
693
+ cursor_id: cursor_id,
694
+ coll_name: collection.name,
695
+ db_name: database.name,
696
+ session: session,
697
+ batch_size: batch_size,
698
+ to_return: 0,
699
+ # max_time_ms is not being passed here, I assume intentionally?
700
+ }
701
+ op = Operation::GetMore.new(spec)
702
+ context = Operation::Context.new(
703
+ client: client,
704
+ session: session,
705
+ service_id: result.connection_description.service_id,
706
+ )
707
+ result = op.execute(server, context: context)
676
708
  Cursor.new(self, result, server, session: session)
677
709
  end
678
710
  end