mongo 1.8.6 → 2.15.1

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 (1640) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/CONTRIBUTING.md +22 -0
  4. data/LICENSE +1 -1
  5. data/README.md +68 -304
  6. data/Rakefile +280 -11
  7. data/bin/mongo_console +18 -13
  8. data/lib/mongo/active_support.rb +20 -0
  9. data/lib/mongo/address/ipv4.rb +128 -0
  10. data/lib/mongo/address/ipv6.rb +142 -0
  11. data/lib/mongo/address/unix.rb +82 -0
  12. data/lib/mongo/address/validator.rb +102 -0
  13. data/lib/mongo/address.rb +296 -0
  14. data/lib/mongo/auth/aws/conversation.rb +128 -0
  15. data/lib/mongo/auth/aws/credentials_retriever.rb +222 -0
  16. data/lib/mongo/auth/aws/request.rb +286 -0
  17. data/lib/mongo/auth/aws.rb +40 -0
  18. data/lib/mongo/auth/base.rb +138 -0
  19. data/lib/mongo/auth/conversation_base.rb +87 -0
  20. data/lib/mongo/auth/cr/conversation.rb +77 -0
  21. data/lib/mongo/auth/cr.rb +45 -0
  22. data/lib/mongo/auth/credential_cache.rb +54 -0
  23. data/lib/mongo/auth/gssapi/conversation.rb +100 -0
  24. data/lib/mongo/auth/gssapi.rb +41 -0
  25. data/lib/mongo/auth/ldap/conversation.rb +57 -0
  26. data/lib/mongo/auth/ldap.rb +42 -0
  27. data/lib/mongo/auth/roles.rb +107 -0
  28. data/lib/mongo/auth/sasl_conversation_base.rb +102 -0
  29. data/lib/mongo/auth/scram/conversation.rb +65 -0
  30. data/lib/mongo/auth/scram.rb +75 -0
  31. data/lib/mongo/auth/scram256/conversation.rb +66 -0
  32. data/lib/mongo/auth/scram256.rb +34 -0
  33. data/lib/mongo/auth/scram_conversation_base.rb +378 -0
  34. data/lib/mongo/auth/stringprep/profiles/sasl.rb +77 -0
  35. data/lib/mongo/auth/stringprep/tables.rb +3236 -0
  36. data/lib/mongo/auth/stringprep/unicode_normalize/normalize.rb +175 -0
  37. data/lib/mongo/auth/stringprep/unicode_normalize/tables.rb +1171 -0
  38. data/lib/mongo/auth/stringprep.rb +118 -0
  39. data/lib/mongo/auth/user/view.rb +165 -0
  40. data/lib/mongo/auth/user.rb +225 -0
  41. data/lib/mongo/auth/x509/conversation.rb +70 -0
  42. data/lib/mongo/auth/x509.rb +60 -0
  43. data/lib/mongo/auth.rb +186 -0
  44. data/lib/mongo/background_thread.rb +173 -0
  45. data/lib/mongo/bson.rb +35 -0
  46. data/lib/mongo/bulk_write/combineable.rb +75 -0
  47. data/lib/mongo/bulk_write/ordered_combiner.rb +58 -0
  48. data/lib/mongo/bulk_write/result.rb +194 -0
  49. data/lib/mongo/bulk_write/result_combiner.rb +133 -0
  50. data/lib/mongo/bulk_write/transformable.rb +156 -0
  51. data/lib/mongo/bulk_write/unordered_combiner.rb +55 -0
  52. data/lib/mongo/bulk_write/validatable.rb +76 -0
  53. data/lib/mongo/bulk_write.rb +289 -0
  54. data/lib/mongo/caching_cursor.rb +77 -0
  55. data/lib/mongo/client.rb +1426 -0
  56. data/lib/mongo/client_encryption.rb +106 -0
  57. data/lib/mongo/cluster/periodic_executor.rb +104 -0
  58. data/lib/mongo/cluster/reapers/cursor_reaper.rb +159 -0
  59. data/lib/mongo/cluster/reapers/socket_reaper.rb +65 -0
  60. data/lib/mongo/cluster/sdam_flow.rb +620 -0
  61. data/lib/mongo/cluster/topology/base.rb +221 -0
  62. data/lib/mongo/cluster/topology/no_replica_set_options.rb +37 -0
  63. data/lib/mongo/cluster/topology/replica_set_no_primary.rb +172 -0
  64. data/lib/mongo/cluster/topology/replica_set_with_primary.rb +30 -0
  65. data/lib/mongo/cluster/topology/sharded.rb +138 -0
  66. data/lib/mongo/cluster/topology/single.rb +147 -0
  67. data/lib/mongo/cluster/topology/unknown.rb +139 -0
  68. data/lib/mongo/cluster/topology.rb +112 -0
  69. data/lib/mongo/cluster.rb +988 -0
  70. data/lib/mongo/cluster_time.rb +142 -0
  71. data/lib/mongo/collection/view/aggregation.rb +166 -0
  72. data/lib/mongo/collection/view/builder/aggregation.rb +142 -0
  73. data/lib/mongo/collection/view/builder/find_command.rb +173 -0
  74. data/lib/mongo/collection/view/builder/flags.rb +65 -0
  75. data/lib/mongo/collection/view/builder/map_reduce.rb +173 -0
  76. data/lib/mongo/collection/view/builder/modifiers.rb +83 -0
  77. data/lib/mongo/collection/view/builder/op_query.rb +94 -0
  78. data/lib/mongo/collection/view/builder.rb +23 -0
  79. data/lib/mongo/collection/view/change_stream/retryable.rb +43 -0
  80. data/lib/mongo/collection/view/change_stream.rb +372 -0
  81. data/lib/mongo/collection/view/explainable.rb +86 -0
  82. data/lib/mongo/collection/view/immutable.rb +39 -0
  83. data/lib/mongo/collection/view/iterable.rb +182 -0
  84. data/lib/mongo/collection/view/map_reduce.rb +279 -0
  85. data/lib/mongo/collection/view/readable.rb +686 -0
  86. data/lib/mongo/collection/view/writable.rb +474 -0
  87. data/lib/mongo/collection/view.rb +223 -0
  88. data/lib/mongo/collection.rb +807 -1016
  89. data/lib/mongo/crypt/auto_decryption_context.rb +43 -0
  90. data/lib/mongo/crypt/auto_encrypter.rb +182 -0
  91. data/lib/mongo/crypt/auto_encryption_context.rb +47 -0
  92. data/lib/mongo/crypt/binary.rb +158 -0
  93. data/lib/mongo/crypt/binding.rb +1232 -0
  94. data/lib/mongo/crypt/context.rb +138 -0
  95. data/lib/mongo/crypt/data_key_context.rb +165 -0
  96. data/lib/mongo/crypt/encryption_io.rb +309 -0
  97. data/lib/mongo/crypt/explicit_decryption_context.rb +43 -0
  98. data/lib/mongo/crypt/explicit_encrypter.rb +120 -0
  99. data/lib/mongo/crypt/explicit_encryption_context.rb +92 -0
  100. data/lib/mongo/crypt/handle.rb +318 -0
  101. data/lib/mongo/crypt/hooks.rb +93 -0
  102. data/lib/mongo/crypt/kms_context.rb +70 -0
  103. data/lib/mongo/crypt/status.rb +134 -0
  104. data/lib/mongo/crypt.rb +36 -0
  105. data/lib/mongo/cursor/builder/get_more_command.rb +80 -0
  106. data/lib/mongo/cursor/builder/kill_cursors_command.rb +111 -0
  107. data/lib/mongo/cursor/builder/op_get_more.rb +64 -0
  108. data/lib/mongo/cursor/builder/op_kill_cursors.rb +106 -0
  109. data/lib/mongo/cursor/builder.rb +21 -0
  110. data/lib/mongo/cursor.rb +336 -505
  111. data/lib/mongo/database/view.rb +199 -0
  112. data/lib/mongo/database.rb +457 -0
  113. data/lib/mongo/dbref.rb +124 -0
  114. data/lib/mongo/distinguishing_semaphore.rb +58 -0
  115. data/lib/mongo/error/auth_error.rb +32 -0
  116. data/lib/mongo/error/bulk_write_error.rb +76 -0
  117. data/lib/mongo/error/change_stream_resumable.rb +40 -0
  118. data/lib/mongo/error/closed_stream.rb +37 -0
  119. data/lib/mongo/error/connection_check_out_timeout.rb +51 -0
  120. data/lib/mongo/error/connection_perished.rb +26 -0
  121. data/lib/mongo/error/credential_check_error.rb +29 -0
  122. data/lib/mongo/error/crypt_error.rb +34 -0
  123. data/lib/mongo/error/extra_file_chunk.rb +37 -0
  124. data/lib/mongo/error/failed_string_prep_validation.rb +41 -0
  125. data/lib/mongo/error/file_not_found.rb +40 -0
  126. data/lib/mongo/error/handshake_error.rb +27 -0
  127. data/lib/mongo/error/insufficient_iteration_count.rb +41 -0
  128. data/lib/mongo/error/internal_driver_error.rb +25 -0
  129. data/lib/mongo/error/invalid_address.rb +27 -0
  130. data/lib/mongo/error/invalid_application_name.rb +41 -0
  131. data/lib/mongo/error/invalid_bulk_operation.rb +40 -0
  132. data/lib/mongo/error/invalid_bulk_operation_type.rb +39 -0
  133. data/lib/mongo/error/invalid_collection_name.rb +42 -0
  134. data/lib/mongo/error/invalid_cursor_operation.rb +30 -0
  135. data/lib/mongo/error/invalid_database_name.rb +42 -0
  136. data/lib/mongo/error/invalid_document.rb +42 -0
  137. data/lib/mongo/error/invalid_file.rb +41 -0
  138. data/lib/mongo/error/invalid_file_revision.rb +40 -0
  139. data/lib/mongo/error/invalid_min_pool_size.rb +38 -0
  140. data/lib/mongo/error/invalid_nonce.rb +49 -0
  141. data/lib/mongo/error/invalid_read_concern.rb +31 -0
  142. data/lib/mongo/error/invalid_read_option.rb +38 -0
  143. data/lib/mongo/error/invalid_replacement_document.rb +42 -0
  144. data/lib/mongo/error/invalid_server_auth_host.rb +25 -0
  145. data/lib/mongo/error/invalid_server_auth_response.rb +26 -0
  146. data/lib/mongo/error/invalid_server_preference.rb +68 -0
  147. data/lib/mongo/error/invalid_session.rb +40 -0
  148. data/lib/mongo/error/invalid_signature.rb +50 -0
  149. data/lib/mongo/error/invalid_transaction_operation.rb +85 -0
  150. data/lib/mongo/error/invalid_txt_record.rb +30 -0
  151. data/lib/mongo/error/invalid_update_document.rb +42 -0
  152. data/lib/mongo/error/invalid_uri.rb +42 -0
  153. data/lib/mongo/error/invalid_write_concern.rb +38 -0
  154. data/lib/mongo/error/kms_error.rb +25 -0
  155. data/lib/mongo/error/lint_error.rb +38 -0
  156. data/lib/mongo/error/max_bson_size.rb +54 -0
  157. data/lib/mongo/error/max_message_size.rb +45 -0
  158. data/lib/mongo/error/mismatched_domain.rb +30 -0
  159. data/lib/mongo/error/missing_file_chunk.rb +41 -0
  160. data/lib/mongo/error/missing_password.rb +32 -0
  161. data/lib/mongo/error/missing_resume_token.rb +42 -0
  162. data/lib/mongo/error/missing_scram_server_signature.rb +30 -0
  163. data/lib/mongo/error/mongocryptd_spawn_error.rb +25 -0
  164. data/lib/mongo/error/multi_index_drop.rb +37 -0
  165. data/lib/mongo/error/need_primary_server.rb +26 -0
  166. data/lib/mongo/error/no_server_available.rb +51 -0
  167. data/lib/mongo/error/no_srv_records.rb +29 -0
  168. data/lib/mongo/error/notable.rb +83 -0
  169. data/lib/mongo/error/operation_failure.rb +311 -0
  170. data/lib/mongo/error/parser.rb +294 -0
  171. data/lib/mongo/error/pool_closed_error.rb +53 -0
  172. data/lib/mongo/error/raise_original_error.rb +32 -0
  173. data/lib/mongo/error/sdam_error_detection.rb +83 -0
  174. data/lib/mongo/error/server_api_conflict.rb +26 -0
  175. data/lib/mongo/error/server_api_not_supported.rb +27 -0
  176. data/lib/mongo/error/server_certificate_revoked.rb +25 -0
  177. data/lib/mongo/error/session_ended.rb +30 -0
  178. data/lib/mongo/error/sessions_not_supported.rb +38 -0
  179. data/lib/mongo/error/socket_error.rb +29 -0
  180. data/lib/mongo/error/socket_timeout_error.rb +29 -0
  181. data/lib/mongo/error/unchangeable_collection_option.rb +41 -0
  182. data/lib/mongo/error/unexpected_chunk_length.rb +42 -0
  183. data/lib/mongo/error/unexpected_response.rb +41 -0
  184. data/lib/mongo/error/unknown_payload_type.rb +44 -0
  185. data/lib/mongo/error/unmet_dependency.rb +24 -0
  186. data/lib/mongo/error/unsupported_array_filters.rb +59 -0
  187. data/lib/mongo/error/unsupported_collation.rb +59 -0
  188. data/lib/mongo/error/unsupported_features.rb +28 -0
  189. data/lib/mongo/error/unsupported_message_type.rb +26 -0
  190. data/lib/mongo/error/unsupported_option.rb +104 -0
  191. data/lib/mongo/error/write_retryable.rb +30 -0
  192. data/lib/mongo/error.rb +246 -0
  193. data/lib/mongo/event/base.rb +45 -0
  194. data/lib/mongo/event/listeners.rb +66 -0
  195. data/lib/mongo/event/publisher.rb +45 -0
  196. data/lib/mongo/event/subscriber.rb +44 -0
  197. data/lib/mongo/event.rb +50 -0
  198. data/lib/mongo/grid/file/chunk.rb +191 -0
  199. data/lib/mongo/grid/file/info.rb +268 -0
  200. data/lib/mongo/grid/file.rb +124 -0
  201. data/lib/mongo/grid/fs_bucket.rb +517 -0
  202. data/lib/mongo/grid/stream/read.rb +244 -0
  203. data/lib/mongo/grid/stream/write.rb +213 -0
  204. data/lib/mongo/grid/stream.rb +67 -0
  205. data/lib/mongo/grid.rb +20 -0
  206. data/lib/mongo/id.rb +67 -0
  207. data/lib/mongo/index/view.rb +358 -0
  208. data/lib/mongo/index.rb +73 -0
  209. data/lib/mongo/lint.rb +105 -0
  210. data/lib/mongo/loggable.rb +112 -0
  211. data/lib/mongo/logger.rb +87 -0
  212. data/lib/mongo/monitoring/cmap_log_subscriber.rb +56 -0
  213. data/lib/mongo/monitoring/command_log_subscriber.rb +132 -0
  214. data/lib/mongo/monitoring/event/cmap/base.rb +31 -0
  215. data/lib/mongo/monitoring/event/cmap/connection_check_out_failed.rb +88 -0
  216. data/lib/mongo/monitoring/event/cmap/connection_check_out_started.rb +59 -0
  217. data/lib/mongo/monitoring/event/cmap/connection_checked_in.rb +74 -0
  218. data/lib/mongo/monitoring/event/cmap/connection_checked_out.rb +75 -0
  219. data/lib/mongo/monitoring/event/cmap/connection_closed.rb +106 -0
  220. data/lib/mongo/monitoring/event/cmap/connection_created.rb +67 -0
  221. data/lib/mongo/monitoring/event/cmap/connection_ready.rb +67 -0
  222. data/lib/mongo/monitoring/event/cmap/pool_cleared.rb +60 -0
  223. data/lib/mongo/monitoring/event/cmap/pool_closed.rb +68 -0
  224. data/lib/mongo/monitoring/event/cmap/pool_created.rb +75 -0
  225. data/lib/mongo/monitoring/event/cmap.rb +28 -0
  226. data/lib/mongo/monitoring/event/command_failed.rb +147 -0
  227. data/lib/mongo/monitoring/event/command_started.rb +183 -0
  228. data/lib/mongo/monitoring/event/command_succeeded.rb +157 -0
  229. data/lib/mongo/monitoring/event/secure.rb +112 -0
  230. data/lib/mongo/monitoring/event/server_closed.rb +62 -0
  231. data/lib/mongo/monitoring/event/server_description_changed.rb +99 -0
  232. data/lib/mongo/monitoring/event/server_heartbeat_failed.rb +92 -0
  233. data/lib/mongo/monitoring/event/server_heartbeat_started.rb +65 -0
  234. data/lib/mongo/monitoring/event/server_heartbeat_succeeded.rb +84 -0
  235. data/lib/mongo/monitoring/event/server_opening.rb +62 -0
  236. data/lib/mongo/monitoring/event/topology_changed.rb +63 -0
  237. data/lib/mongo/monitoring/event/topology_closed.rb +57 -0
  238. data/lib/mongo/monitoring/event/topology_opening.rb +57 -0
  239. data/lib/mongo/monitoring/event.rb +32 -0
  240. data/lib/mongo/monitoring/publishable.rb +122 -0
  241. data/lib/mongo/monitoring/sdam_log_subscriber.rb +57 -0
  242. data/lib/mongo/monitoring/server_closed_log_subscriber.rb +33 -0
  243. data/lib/mongo/monitoring/server_description_changed_log_subscriber.rb +44 -0
  244. data/lib/mongo/monitoring/server_opening_log_subscriber.rb +33 -0
  245. data/lib/mongo/monitoring/topology_changed_log_subscriber.rb +43 -0
  246. data/lib/mongo/monitoring/topology_closed_log_subscriber.rb +33 -0
  247. data/lib/mongo/monitoring/topology_opening_log_subscriber.rb +33 -0
  248. data/lib/mongo/monitoring/unified_sdam_log_subscriber.rb +65 -0
  249. data/lib/mongo/monitoring.rb +379 -0
  250. data/lib/mongo/operation/aggregate/command.rb +47 -0
  251. data/lib/mongo/operation/aggregate/op_msg.rb +34 -0
  252. data/lib/mongo/operation/aggregate/result.rb +104 -0
  253. data/lib/mongo/operation/aggregate.rb +39 -0
  254. data/lib/mongo/operation/collections_info/command.rb +48 -0
  255. data/lib/mongo/operation/collections_info/result.rb +59 -0
  256. data/lib/mongo/operation/collections_info.rb +51 -0
  257. data/lib/mongo/operation/command/command.rb +41 -0
  258. data/lib/mongo/operation/command/op_msg.rb +31 -0
  259. data/lib/mongo/operation/command.rb +34 -0
  260. data/lib/mongo/operation/context.rb +102 -0
  261. data/lib/mongo/operation/count/command.rb +41 -0
  262. data/lib/mongo/operation/count/op_msg.rb +32 -0
  263. data/lib/mongo/operation/count.rb +34 -0
  264. data/lib/mongo/operation/create/command.rb +41 -0
  265. data/lib/mongo/operation/create/op_msg.rb +32 -0
  266. data/lib/mongo/operation/create.rb +34 -0
  267. data/lib/mongo/operation/create_index/command.rb +45 -0
  268. data/lib/mongo/operation/create_index/op_msg.rb +41 -0
  269. data/lib/mongo/operation/create_index.rb +34 -0
  270. data/lib/mongo/operation/create_user/command.rb +46 -0
  271. data/lib/mongo/operation/create_user/op_msg.rb +38 -0
  272. data/lib/mongo/operation/create_user.rb +34 -0
  273. data/lib/mongo/operation/delete/bulk_result.rb +51 -0
  274. data/lib/mongo/operation/delete/command.rb +49 -0
  275. data/lib/mongo/operation/delete/legacy.rb +57 -0
  276. data/lib/mongo/operation/delete/op_msg.rb +48 -0
  277. data/lib/mongo/operation/delete/result.rb +48 -0
  278. data/lib/mongo/operation/delete.rb +41 -0
  279. data/lib/mongo/operation/distinct/command.rb +41 -0
  280. data/lib/mongo/operation/distinct/op_msg.rb +33 -0
  281. data/lib/mongo/operation/distinct.rb +34 -0
  282. data/lib/mongo/operation/drop/command.rb +41 -0
  283. data/lib/mongo/operation/drop/op_msg.rb +32 -0
  284. data/lib/mongo/operation/drop.rb +34 -0
  285. data/lib/mongo/operation/drop_database/command.rb +41 -0
  286. data/lib/mongo/operation/drop_database/op_msg.rb +32 -0
  287. data/lib/mongo/operation/drop_database.rb +34 -0
  288. data/lib/mongo/operation/drop_index/command.rb +45 -0
  289. data/lib/mongo/operation/drop_index/op_msg.rb +38 -0
  290. data/lib/mongo/operation/drop_index.rb +34 -0
  291. data/lib/mongo/operation/explain/command.rb +46 -0
  292. data/lib/mongo/operation/explain/legacy.rb +45 -0
  293. data/lib/mongo/operation/explain/op_msg.rb +40 -0
  294. data/lib/mongo/operation/explain/result.rb +56 -0
  295. data/lib/mongo/operation/explain.rb +36 -0
  296. data/lib/mongo/operation/find/command.rb +42 -0
  297. data/lib/mongo/operation/find/legacy/result.rb +46 -0
  298. data/lib/mongo/operation/find/legacy.rb +43 -0
  299. data/lib/mongo/operation/find/op_msg.rb +34 -0
  300. data/lib/mongo/operation/find/result.rb +76 -0
  301. data/lib/mongo/operation/find.rb +36 -0
  302. data/lib/mongo/operation/get_more/command.rb +42 -0
  303. data/lib/mongo/operation/get_more/legacy.rb +39 -0
  304. data/lib/mongo/operation/get_more/op_msg.rb +33 -0
  305. data/lib/mongo/operation/get_more/result.rb +75 -0
  306. data/lib/mongo/operation/get_more.rb +36 -0
  307. data/lib/mongo/operation/indexes/command.rb +42 -0
  308. data/lib/mongo/operation/indexes/legacy.rb +48 -0
  309. data/lib/mongo/operation/indexes/op_msg.rb +34 -0
  310. data/lib/mongo/operation/indexes/result.rb +105 -0
  311. data/lib/mongo/operation/indexes.rb +50 -0
  312. data/lib/mongo/operation/insert/bulk_result.rb +112 -0
  313. data/lib/mongo/operation/insert/command.rb +59 -0
  314. data/lib/mongo/operation/insert/legacy.rb +68 -0
  315. data/lib/mongo/operation/insert/op_msg.rb +54 -0
  316. data/lib/mongo/operation/insert/result.rb +75 -0
  317. data/lib/mongo/operation/insert.rb +44 -0
  318. data/lib/mongo/operation/kill_cursors/command.rb +40 -0
  319. data/lib/mongo/operation/kill_cursors/legacy.rb +40 -0
  320. data/lib/mongo/operation/kill_cursors/op_msg.rb +32 -0
  321. data/lib/mongo/operation/kill_cursors.rb +35 -0
  322. data/lib/mongo/operation/list_collections/command.rb +46 -0
  323. data/lib/mongo/operation/list_collections/op_msg.rb +39 -0
  324. data/lib/mongo/operation/list_collections/result.rb +113 -0
  325. data/lib/mongo/operation/list_collections.rb +35 -0
  326. data/lib/mongo/operation/map_reduce/command.rb +43 -0
  327. data/lib/mongo/operation/map_reduce/op_msg.rb +34 -0
  328. data/lib/mongo/operation/map_reduce/result.rb +142 -0
  329. data/lib/mongo/operation/map_reduce.rb +35 -0
  330. data/lib/mongo/operation/op_msg_base.rb +33 -0
  331. data/lib/mongo/operation/parallel_scan/command.rb +57 -0
  332. data/lib/mongo/operation/parallel_scan/op_msg.rb +46 -0
  333. data/lib/mongo/operation/parallel_scan/result.rb +68 -0
  334. data/lib/mongo/operation/parallel_scan.rb +35 -0
  335. data/lib/mongo/operation/remove_user/command.rb +46 -0
  336. data/lib/mongo/operation/remove_user/op_msg.rb +38 -0
  337. data/lib/mongo/operation/remove_user.rb +34 -0
  338. data/lib/mongo/operation/result.rb +461 -0
  339. data/lib/mongo/operation/shared/bypass_document_validation.rb +46 -0
  340. data/lib/mongo/operation/shared/causal_consistency_supported.rb +45 -0
  341. data/lib/mongo/operation/shared/executable.rb +116 -0
  342. data/lib/mongo/operation/shared/executable_no_validate.rb +32 -0
  343. data/lib/mongo/operation/shared/executable_transaction_label.rb +30 -0
  344. data/lib/mongo/operation/shared/idable.rb +68 -0
  345. data/lib/mongo/operation/shared/limited.rb +42 -0
  346. data/lib/mongo/operation/shared/object_id_generator.rb +40 -0
  347. data/lib/mongo/operation/shared/op_msg_or_command.rb +41 -0
  348. data/lib/mongo/operation/shared/op_msg_or_find_command.rb +44 -0
  349. data/lib/mongo/operation/shared/polymorphic_lookup.rb +36 -0
  350. data/lib/mongo/operation/shared/polymorphic_operation.rb +42 -0
  351. data/lib/mongo/operation/shared/polymorphic_result.rb +50 -0
  352. data/lib/mongo/operation/shared/read_preference_supported.rb +114 -0
  353. data/lib/mongo/operation/shared/response_handling.rb +172 -0
  354. data/lib/mongo/operation/shared/result/aggregatable.rb +74 -0
  355. data/lib/mongo/operation/shared/result/use_legacy_error_parser.rb +32 -0
  356. data/lib/mongo/operation/shared/sessions_supported.rb +254 -0
  357. data/lib/mongo/operation/shared/specifiable.rb +585 -0
  358. data/lib/mongo/operation/shared/write.rb +90 -0
  359. data/lib/mongo/operation/shared/write_concern_supported.rb +43 -0
  360. data/lib/mongo/operation/update/bulk_result.rb +129 -0
  361. data/lib/mongo/operation/update/command.rb +50 -0
  362. data/lib/mongo/operation/update/legacy/result.rb +112 -0
  363. data/lib/mongo/operation/update/legacy.rb +68 -0
  364. data/lib/mongo/operation/update/op_msg.rb +48 -0
  365. data/lib/mongo/operation/update/result.rb +113 -0
  366. data/lib/mongo/operation/update.rb +41 -0
  367. data/lib/mongo/operation/update_user/command.rb +45 -0
  368. data/lib/mongo/operation/update_user/op_msg.rb +38 -0
  369. data/lib/mongo/operation/update_user.rb +34 -0
  370. data/lib/mongo/operation/users_info/command.rb +46 -0
  371. data/lib/mongo/operation/users_info/op_msg.rb +39 -0
  372. data/lib/mongo/operation/users_info/result.rb +48 -0
  373. data/lib/mongo/operation/users_info.rb +35 -0
  374. data/lib/mongo/operation.rb +106 -0
  375. data/lib/mongo/options/mapper.rb +129 -0
  376. data/lib/mongo/options/redacted.rb +159 -0
  377. data/lib/mongo/options.rb +19 -0
  378. data/lib/mongo/protocol/bit_vector.rb +67 -0
  379. data/lib/mongo/protocol/compressed.rb +184 -0
  380. data/lib/mongo/protocol/delete.rb +172 -0
  381. data/lib/mongo/protocol/get_more.rb +165 -0
  382. data/lib/mongo/protocol/insert.rb +181 -0
  383. data/lib/mongo/protocol/kill_cursors.rb +133 -0
  384. data/lib/mongo/protocol/message.rb +465 -0
  385. data/lib/mongo/protocol/msg.rb +404 -0
  386. data/lib/mongo/protocol/query.rb +356 -0
  387. data/lib/mongo/protocol/registry.rb +79 -0
  388. data/lib/mongo/protocol/reply.rb +207 -0
  389. data/lib/mongo/protocol/serializers.rb +460 -0
  390. data/lib/mongo/protocol/update.rb +214 -0
  391. data/lib/mongo/protocol.rb +21 -0
  392. data/lib/mongo/query_cache.rb +275 -0
  393. data/lib/mongo/retryable.rb +496 -0
  394. data/lib/mongo/semaphore.rb +49 -0
  395. data/lib/mongo/server/app_metadata.rb +267 -0
  396. data/lib/mongo/server/connection.rb +326 -0
  397. data/lib/mongo/server/connection_base.rb +265 -0
  398. data/lib/mongo/server/connection_common.rb +168 -0
  399. data/lib/mongo/server/connection_pool/populator.rb +61 -0
  400. data/lib/mongo/server/connection_pool.rb +802 -0
  401. data/lib/mongo/server/context.rb +72 -0
  402. data/lib/mongo/server/description/features.rb +151 -0
  403. data/lib/mongo/server/description.rb +832 -0
  404. data/lib/mongo/server/monitor/app_metadata.rb +37 -0
  405. data/lib/mongo/server/monitor/connection.rb +269 -0
  406. data/lib/mongo/server/monitor.rb +339 -0
  407. data/lib/mongo/server/pending_connection.rb +272 -0
  408. data/lib/mongo/server/push_monitor/connection.rb +31 -0
  409. data/lib/mongo/server/push_monitor.rb +194 -0
  410. data/lib/mongo/server/round_trip_time_averager.rb +76 -0
  411. data/lib/mongo/server.rb +584 -0
  412. data/lib/mongo/server_selector/base.rb +625 -0
  413. data/lib/mongo/server_selector/nearest.rb +110 -0
  414. data/lib/mongo/server_selector/primary.rb +110 -0
  415. data/lib/mongo/server_selector/primary_preferred.rb +115 -0
  416. data/lib/mongo/server_selector/secondary.rb +109 -0
  417. data/lib/mongo/server_selector/secondary_preferred.rb +113 -0
  418. data/lib/mongo/server_selector.rb +91 -0
  419. data/lib/mongo/session/server_session.rb +122 -0
  420. data/lib/mongo/session/session_pool.rb +155 -0
  421. data/lib/mongo/session.rb +1074 -0
  422. data/lib/mongo/socket/ocsp_cache.rb +100 -0
  423. data/lib/mongo/socket/ocsp_verifier.rb +376 -0
  424. data/lib/mongo/socket/ssl.rb +395 -0
  425. data/lib/mongo/socket/tcp.rb +97 -0
  426. data/lib/mongo/socket/unix.rb +63 -0
  427. data/lib/mongo/socket.rb +463 -0
  428. data/lib/mongo/srv/monitor.rb +113 -0
  429. data/lib/mongo/srv/resolver.rb +137 -0
  430. data/lib/mongo/srv/result.rb +128 -0
  431. data/lib/mongo/srv.rb +20 -0
  432. data/lib/mongo/timeout.rb +54 -0
  433. data/lib/mongo/topology_version.rb +92 -0
  434. data/lib/mongo/uri/options_mapper.rb +623 -0
  435. data/lib/mongo/uri/srv_protocol.rb +241 -0
  436. data/lib/mongo/uri.rb +528 -0
  437. data/lib/mongo/utils.rb +118 -0
  438. data/lib/mongo/version.rb +24 -0
  439. data/lib/mongo/write_concern/acknowledged.rb +65 -0
  440. data/lib/mongo/write_concern/base.rb +70 -0
  441. data/lib/mongo/write_concern/unacknowledged.rb +68 -0
  442. data/lib/mongo/write_concern.rb +99 -0
  443. data/lib/mongo.rb +98 -71
  444. data/mongo.gemspec +29 -18
  445. data/spec/NOTES.aws-auth.md +296 -0
  446. data/spec/README.aws-auth.md +318 -0
  447. data/spec/README.md +715 -0
  448. data/spec/USERS.md +72 -0
  449. data/spec/atlas/atlas_connectivity_spec.rb +27 -0
  450. data/spec/atlas/operations_spec.rb +28 -0
  451. data/spec/integration/auth_spec.rb +279 -0
  452. data/spec/integration/awaited_ismaster_spec.rb +31 -0
  453. data/spec/integration/aws_auth_request_spec.rb +77 -0
  454. data/spec/integration/aws_credentials_retriever_spec.rb +106 -0
  455. data/spec/integration/bson_symbol_spec.rb +39 -0
  456. data/spec/integration/bulk_insert_spec.rb +83 -0
  457. data/spec/integration/bulk_write_error_message_spec.rb +41 -0
  458. data/spec/integration/bulk_write_spec.rb +70 -0
  459. data/spec/integration/change_stream_examples_spec.rb +208 -0
  460. data/spec/integration/change_stream_spec.rb +808 -0
  461. data/spec/integration/check_clean_slate_spec.rb +19 -0
  462. data/spec/integration/client_authentication_options_spec.rb +514 -0
  463. data/spec/integration/client_connectivity_spec.rb +41 -0
  464. data/spec/integration/client_construction_aws_auth_spec.rb +194 -0
  465. data/spec/integration/client_construction_spec.rb +239 -0
  466. data/spec/integration/client_side_encryption/auto_encryption_bulk_writes_spec.rb +360 -0
  467. data/spec/integration/client_side_encryption/auto_encryption_command_monitoring_spec.rb +306 -0
  468. data/spec/integration/client_side_encryption/auto_encryption_mongocryptd_spawn_spec.rb +75 -0
  469. data/spec/integration/client_side_encryption/auto_encryption_old_wire_version_spec.rb +82 -0
  470. data/spec/integration/client_side_encryption/auto_encryption_reconnect_spec.rb +224 -0
  471. data/spec/integration/client_side_encryption/auto_encryption_spec.rb +604 -0
  472. data/spec/integration/client_side_encryption/bson_size_limit_spec.rb +190 -0
  473. data/spec/integration/client_side_encryption/bypass_mongocryptd_spawn_spec.rb +81 -0
  474. data/spec/integration/client_side_encryption/client_close_spec.rb +66 -0
  475. data/spec/integration/client_side_encryption/corpus_spec.rb +236 -0
  476. data/spec/integration/client_side_encryption/custom_endpoint_spec.rb +135 -0
  477. data/spec/integration/client_side_encryption/data_key_spec.rb +168 -0
  478. data/spec/integration/client_side_encryption/explicit_encryption_spec.rb +117 -0
  479. data/spec/integration/client_side_encryption/external_key_vault_spec.rb +144 -0
  480. data/spec/integration/client_side_encryption/views_spec.rb +47 -0
  481. data/spec/integration/client_spec.rb +47 -0
  482. data/spec/integration/client_update_spec.rb +157 -0
  483. data/spec/integration/collection_indexes_prose_spec.rb +58 -0
  484. data/spec/integration/command_monitoring_spec.rb +184 -0
  485. data/spec/integration/command_spec.rb +179 -0
  486. data/spec/integration/connect_single_rs_name_spec.rb +75 -0
  487. data/spec/integration/connection_pool_populator_spec.rb +305 -0
  488. data/spec/integration/connection_spec.rb +336 -0
  489. data/spec/integration/crud_spec.rb +193 -0
  490. data/spec/integration/cursor_reaping_spec.rb +139 -0
  491. data/spec/integration/docs_examples_spec.rb +207 -0
  492. data/spec/integration/error_detection_spec.rb +42 -0
  493. data/spec/integration/fork_reconnect_spec.rb +204 -0
  494. data/spec/integration/get_more_spec.rb +42 -0
  495. data/spec/integration/grid_fs_bucket_spec.rb +51 -0
  496. data/spec/integration/heartbeat_events_spec.rb +102 -0
  497. data/spec/integration/mmapv1_spec.rb +31 -0
  498. data/spec/integration/mongos_pinning_spec.rb +37 -0
  499. data/spec/integration/ocsp_connectivity_spec.rb +29 -0
  500. data/spec/integration/ocsp_verifier_cache_spec.rb +191 -0
  501. data/spec/integration/ocsp_verifier_spec.rb +355 -0
  502. data/spec/integration/operation_failure_code_spec.rb +29 -0
  503. data/spec/integration/operation_failure_message_spec.rb +90 -0
  504. data/spec/integration/query_cache_spec.rb +1093 -0
  505. data/spec/integration/query_cache_transactions_spec.rb +193 -0
  506. data/spec/integration/read_concern_spec.rb +92 -0
  507. data/spec/integration/read_preference_spec.rb +544 -0
  508. data/spec/integration/reconnect_spec.rb +177 -0
  509. data/spec/integration/retryable_errors_spec.rb +286 -0
  510. data/spec/integration/retryable_writes/retryable_writes_36_and_older_spec.rb +764 -0
  511. data/spec/integration/retryable_writes/retryable_writes_40_and_newer_spec.rb +405 -0
  512. data/spec/integration/retryable_writes/shared/adds_diagnostics.rb +18 -0
  513. data/spec/integration/retryable_writes/shared/does_not_support_retries.rb +27 -0
  514. data/spec/integration/retryable_writes/shared/only_supports_legacy_retries.rb +28 -0
  515. data/spec/integration/retryable_writes/shared/performs_legacy_retries.rb +220 -0
  516. data/spec/integration/retryable_writes/shared/performs_modern_retries.rb +235 -0
  517. data/spec/integration/retryable_writes/shared/performs_no_retries.rb +113 -0
  518. data/spec/integration/retryable_writes/shared/supports_legacy_retries.rb +22 -0
  519. data/spec/integration/retryable_writes/shared/supports_modern_retries.rb +28 -0
  520. data/spec/integration/retryable_writes/shared/supports_retries.rb +19 -0
  521. data/spec/integration/retryable_writes_errors_spec.rb +34 -0
  522. data/spec/integration/sdam_error_handling_spec.rb +424 -0
  523. data/spec/integration/sdam_events_spec.rb +122 -0
  524. data/spec/integration/sdam_prose_spec.rb +67 -0
  525. data/spec/integration/secondary_reads_spec.rb +102 -0
  526. data/spec/integration/server_description_spec.rb +48 -0
  527. data/spec/integration/server_monitor_spec.rb +55 -0
  528. data/spec/integration/server_selection_spec.rb +39 -0
  529. data/spec/integration/server_selector_spec.rb +88 -0
  530. data/spec/integration/server_spec.rb +67 -0
  531. data/spec/integration/shell_examples_spec.rb +984 -0
  532. data/spec/integration/size_limit_spec.rb +115 -0
  533. data/spec/integration/snappy_compression_spec.rb +28 -0
  534. data/spec/integration/srv_monitoring_spec.rb +406 -0
  535. data/spec/integration/srv_spec.rb +59 -0
  536. data/spec/integration/ssl_uri_options_spec.rb +28 -0
  537. data/spec/integration/step_down_spec.rb +207 -0
  538. data/spec/integration/time_zone_querying_spec.rb +55 -0
  539. data/spec/integration/transactions_api_examples_spec.rb +62 -0
  540. data/spec/integration/transactions_examples_spec.rb +235 -0
  541. data/spec/integration/truncated_utf8_spec.rb +26 -0
  542. data/spec/integration/versioned_api_examples_spec.rb +69 -0
  543. data/spec/integration/x509_auth_spec.rb +112 -0
  544. data/spec/integration/zlib_compression_spec.rb +28 -0
  545. data/spec/integration/zstd_compression_spec.rb +29 -0
  546. data/spec/kerberos/kerberos_spec.rb +94 -0
  547. data/spec/lite_spec_helper.rb +168 -0
  548. data/spec/mongo/address/ipv4_spec.rb +102 -0
  549. data/spec/mongo/address/ipv6_spec.rb +130 -0
  550. data/spec/mongo/address/unix_spec.rb +44 -0
  551. data/spec/mongo/address/validator_spec.rb +54 -0
  552. data/spec/mongo/address_spec.rb +344 -0
  553. data/spec/mongo/auth/aws/request_region_spec.rb +45 -0
  554. data/spec/mongo/auth/aws/request_spec.rb +79 -0
  555. data/spec/mongo/auth/cr_spec.rb +79 -0
  556. data/spec/mongo/auth/gssapi/conversation_spec.rb +124 -0
  557. data/spec/mongo/auth/invalid_mechanism_spec.rb +14 -0
  558. data/spec/mongo/auth/ldap/conversation_spec.rb +46 -0
  559. data/spec/mongo/auth/ldap_spec.rb +47 -0
  560. data/spec/mongo/auth/scram/conversation_spec.rb +205 -0
  561. data/spec/mongo/auth/scram256/conversation_spec.rb +174 -0
  562. data/spec/mongo/auth/scram_negotiation_spec.rb +531 -0
  563. data/spec/mongo/auth/scram_spec.rb +122 -0
  564. data/spec/mongo/auth/stringprep/profiles/sasl_spec.rb +116 -0
  565. data/spec/mongo/auth/stringprep_spec.rb +191 -0
  566. data/spec/mongo/auth/user/view_spec.rb +489 -0
  567. data/spec/mongo/auth/user_spec.rb +343 -0
  568. data/spec/mongo/auth/x509/conversation_spec.rb +72 -0
  569. data/spec/mongo/auth/x509_spec.rb +73 -0
  570. data/spec/mongo/auth_spec.rb +68 -0
  571. data/spec/mongo/bson_spec.rb +14 -0
  572. data/spec/mongo/bulk_write/ordered_combiner_spec.rb +287 -0
  573. data/spec/mongo/bulk_write/result_spec.rb +127 -0
  574. data/spec/mongo/bulk_write/unordered_combiner_spec.rb +242 -0
  575. data/spec/mongo/bulk_write_spec.rb +2393 -0
  576. data/spec/mongo/caching_cursor_spec.rb +73 -0
  577. data/spec/mongo/client_construction_spec.rb +2389 -0
  578. data/spec/mongo/client_encryption_spec.rb +414 -0
  579. data/spec/mongo/client_spec.rb +964 -0
  580. data/spec/mongo/cluster/cursor_reaper_spec.rb +190 -0
  581. data/spec/mongo/cluster/periodic_executor_spec.rb +19 -0
  582. data/spec/mongo/cluster/socket_reaper_spec.rb +46 -0
  583. data/spec/mongo/cluster/topology/replica_set_spec.rb +601 -0
  584. data/spec/mongo/cluster/topology/sharded_spec.rb +158 -0
  585. data/spec/mongo/cluster/topology/single_spec.rb +192 -0
  586. data/spec/mongo/cluster/topology/unknown_spec.rb +103 -0
  587. data/spec/mongo/cluster/topology_spec.rb +211 -0
  588. data/spec/mongo/cluster_spec.rb +790 -0
  589. data/spec/mongo/cluster_time_spec.rb +151 -0
  590. data/spec/mongo/collection/view/aggregation_spec.rb +678 -0
  591. data/spec/mongo/collection/view/builder/find_command_spec.rb +524 -0
  592. data/spec/mongo/collection/view/builder/flags_spec.rb +109 -0
  593. data/spec/mongo/collection/view/builder/modifiers_spec.rb +213 -0
  594. data/spec/mongo/collection/view/builder/op_query_spec.rb +157 -0
  595. data/spec/mongo/collection/view/change_stream_resume_spec.rb +397 -0
  596. data/spec/mongo/collection/view/change_stream_spec.rb +547 -0
  597. data/spec/mongo/collection/view/explainable_spec.rb +117 -0
  598. data/spec/mongo/collection/view/immutable_spec.rb +57 -0
  599. data/spec/mongo/collection/view/iterable_spec.rb +41 -0
  600. data/spec/mongo/collection/view/map_reduce_spec.rb +868 -0
  601. data/spec/mongo/collection/view/readable_spec.rb +1485 -0
  602. data/spec/mongo/collection/view/writable_spec.rb +1864 -0
  603. data/spec/mongo/collection/view_spec.rb +424 -0
  604. data/spec/mongo/collection_crud_spec.rb +4360 -0
  605. data/spec/mongo/collection_ddl_spec.rb +537 -0
  606. data/spec/mongo/collection_spec.rb +804 -0
  607. data/spec/mongo/crypt/auto_decryption_context_spec.rb +93 -0
  608. data/spec/mongo/crypt/auto_encrypter_spec.rb +190 -0
  609. data/spec/mongo/crypt/auto_encryption_context_spec.rb +110 -0
  610. data/spec/mongo/crypt/binary_spec.rb +113 -0
  611. data/spec/mongo/crypt/binding/binary_spec.rb +54 -0
  612. data/spec/mongo/crypt/binding/context_spec.rb +255 -0
  613. data/spec/mongo/crypt/binding/helpers_spec.rb +44 -0
  614. data/spec/mongo/crypt/binding/mongocrypt_spec.rb +142 -0
  615. data/spec/mongo/crypt/binding/status_spec.rb +97 -0
  616. data/spec/mongo/crypt/binding/version_spec.rb +20 -0
  617. data/spec/mongo/crypt/binding_unloaded_spec.rb +23 -0
  618. data/spec/mongo/crypt/data_key_context_spec.rb +216 -0
  619. data/spec/mongo/crypt/encryption_io_spec.rb +139 -0
  620. data/spec/mongo/crypt/explicit_decryption_context_spec.rb +75 -0
  621. data/spec/mongo/crypt/explicit_encryption_context_spec.rb +173 -0
  622. data/spec/mongo/crypt/handle_spec.rb +235 -0
  623. data/spec/mongo/crypt/helpers/mongo_crypt_spec_helper.rb +111 -0
  624. data/spec/mongo/crypt/status_spec.rb +150 -0
  625. data/spec/mongo/cursor/builder/get_more_command_spec.rb +191 -0
  626. data/spec/mongo/cursor/builder/op_get_more_spec.rb +64 -0
  627. data/spec/mongo/cursor/builder/op_kill_cursors_spec.rb +66 -0
  628. data/spec/mongo/cursor_spec.rb +690 -0
  629. data/spec/mongo/database_spec.rb +1300 -0
  630. data/spec/mongo/dbref_spec.rb +152 -0
  631. data/spec/mongo/distinguishing_semaphore_spec.rb +66 -0
  632. data/spec/mongo/error/bulk_write_error_spec.rb +52 -0
  633. data/spec/mongo/error/crypt_error_spec.rb +29 -0
  634. data/spec/mongo/error/max_bson_size_spec.rb +38 -0
  635. data/spec/mongo/error/no_server_available_spec.rb +35 -0
  636. data/spec/mongo/error/notable_spec.rb +62 -0
  637. data/spec/mongo/error/operation_failure_heavy_spec.rb +61 -0
  638. data/spec/mongo/error/operation_failure_spec.rb +553 -0
  639. data/spec/mongo/error/parser_spec.rb +519 -0
  640. data/spec/mongo/error/unsupported_option_spec.rb +57 -0
  641. data/spec/mongo/event/publisher_spec.rb +53 -0
  642. data/spec/mongo/event/subscriber_spec.rb +37 -0
  643. data/spec/mongo/grid/file/chunk_spec.rb +230 -0
  644. data/spec/mongo/grid/file/info_spec.rb +107 -0
  645. data/spec/mongo/grid/file_spec.rb +194 -0
  646. data/spec/mongo/grid/fs_bucket_spec.rb +1263 -0
  647. data/spec/mongo/grid/stream/read_spec.rb +292 -0
  648. data/spec/mongo/grid/stream/write_spec.rb +565 -0
  649. data/spec/mongo/grid/stream_spec.rb +51 -0
  650. data/spec/mongo/id_spec.rb +38 -0
  651. data/spec/mongo/index/view_spec.rb +1171 -0
  652. data/spec/mongo/lint_spec.rb +231 -0
  653. data/spec/mongo/logger_spec.rb +62 -0
  654. data/spec/mongo/monitoring/command_log_subscriber_spec.rb +79 -0
  655. data/spec/mongo/monitoring/event/cmap/connection_check_out_failed_spec.rb +26 -0
  656. data/spec/mongo/monitoring/event/cmap/connection_check_out_started_spec.rb +22 -0
  657. data/spec/mongo/monitoring/event/cmap/connection_checked_in_spec.rb +33 -0
  658. data/spec/mongo/monitoring/event/cmap/connection_checked_out_spec.rb +33 -0
  659. data/spec/mongo/monitoring/event/cmap/connection_closed_spec.rb +30 -0
  660. data/spec/mongo/monitoring/event/cmap/connection_created_spec.rb +27 -0
  661. data/spec/mongo/monitoring/event/cmap/connection_ready_spec.rb +27 -0
  662. data/spec/mongo/monitoring/event/cmap/pool_cleared_spec.rb +22 -0
  663. data/spec/mongo/monitoring/event/cmap/pool_closed_spec.rb +29 -0
  664. data/spec/mongo/monitoring/event/cmap/pool_created_spec.rb +36 -0
  665. data/spec/mongo/monitoring/event/command_failed_spec.rb +87 -0
  666. data/spec/mongo/monitoring/event/command_started_spec.rb +51 -0
  667. data/spec/mongo/monitoring/event/command_succeeded_spec.rb +88 -0
  668. data/spec/mongo/monitoring/event/secure_spec.rb +123 -0
  669. data/spec/mongo/monitoring/event/server_closed_spec.rb +38 -0
  670. data/spec/mongo/monitoring/event/server_description_changed_spec.rb +38 -0
  671. data/spec/mongo/monitoring/event/server_heartbeat_failed_spec.rb +34 -0
  672. data/spec/mongo/monitoring/event/server_heartbeat_started_spec.rb +34 -0
  673. data/spec/mongo/monitoring/event/server_heartbeat_succeeded_spec.rb +34 -0
  674. data/spec/mongo/monitoring/event/server_opening_spec.rb +38 -0
  675. data/spec/mongo/monitoring/event/topology_changed_spec.rb +44 -0
  676. data/spec/mongo/monitoring/event/topology_closed_spec.rb +38 -0
  677. data/spec/mongo/monitoring/event/topology_opening_spec.rb +38 -0
  678. data/spec/mongo/monitoring_spec.rb +196 -0
  679. data/spec/mongo/operation/aggregate/result_spec.rb +90 -0
  680. data/spec/mongo/operation/aggregate_spec.rb +76 -0
  681. data/spec/mongo/operation/collections_info_spec.rb +48 -0
  682. data/spec/mongo/operation/command_spec.rb +86 -0
  683. data/spec/mongo/operation/create_index_spec.rb +62 -0
  684. data/spec/mongo/operation/create_user_spec.rb +53 -0
  685. data/spec/mongo/operation/delete/bulk_spec.rb +245 -0
  686. data/spec/mongo/operation/delete/command_spec.rb +115 -0
  687. data/spec/mongo/operation/delete/op_msg_spec.rb +257 -0
  688. data/spec/mongo/operation/delete_spec.rb +233 -0
  689. data/spec/mongo/operation/drop_index_spec.rb +61 -0
  690. data/spec/mongo/operation/find/legacy_spec.rb +130 -0
  691. data/spec/mongo/operation/get_more_spec.rb +63 -0
  692. data/spec/mongo/operation/indexes_spec.rb +41 -0
  693. data/spec/mongo/operation/insert/bulk_spec.rb +273 -0
  694. data/spec/mongo/operation/insert/command_spec.rb +118 -0
  695. data/spec/mongo/operation/insert/op_msg_spec.rb +288 -0
  696. data/spec/mongo/operation/insert_spec.rb +290 -0
  697. data/spec/mongo/operation/kill_cursors_spec.rb +44 -0
  698. data/spec/mongo/operation/limited_spec.rb +55 -0
  699. data/spec/mongo/operation/map_reduce_spec.rb +131 -0
  700. data/spec/mongo/operation/read_preference_legacy_spec.rb +356 -0
  701. data/spec/mongo/operation/read_preference_op_msg_spec.rb +307 -0
  702. data/spec/mongo/operation/remove_user_spec.rb +52 -0
  703. data/spec/mongo/operation/result_spec.rb +349 -0
  704. data/spec/mongo/operation/specifiable_spec.rb +87 -0
  705. data/spec/mongo/operation/update/bulk_spec.rb +239 -0
  706. data/spec/mongo/operation/update/command_spec.rb +122 -0
  707. data/spec/mongo/operation/update/op_msg_spec.rb +263 -0
  708. data/spec/mongo/operation/update_spec.rb +264 -0
  709. data/spec/mongo/operation/update_user_spec.rb +52 -0
  710. data/spec/mongo/options/redacted_spec.rb +353 -0
  711. data/spec/mongo/protocol/compressed_spec.rb +83 -0
  712. data/spec/mongo/protocol/delete_spec.rb +185 -0
  713. data/spec/mongo/protocol/get_more_spec.rb +164 -0
  714. data/spec/mongo/protocol/insert_spec.rb +179 -0
  715. data/spec/mongo/protocol/kill_cursors_spec.rb +121 -0
  716. data/spec/mongo/protocol/msg_spec.rb +528 -0
  717. data/spec/mongo/protocol/query_spec.rb +347 -0
  718. data/spec/mongo/protocol/registry_spec.rb +34 -0
  719. data/spec/mongo/protocol/reply_spec.rb +198 -0
  720. data/spec/mongo/protocol/update_spec.rb +204 -0
  721. data/spec/mongo/query_cache_middleware_spec.rb +55 -0
  722. data/spec/mongo/query_cache_spec.rb +283 -0
  723. data/spec/mongo/retryable_spec.rb +592 -0
  724. data/spec/mongo/semaphore_spec.rb +54 -0
  725. data/spec/mongo/server/app_metadata_spec.rb +170 -0
  726. data/spec/mongo/server/connection_auth_spec.rb +136 -0
  727. data/spec/mongo/server/connection_common_spec.rb +24 -0
  728. data/spec/mongo/server/connection_pool/populator_spec.rb +106 -0
  729. data/spec/mongo/server/connection_pool_spec.rb +1039 -0
  730. data/spec/mongo/server/connection_spec.rb +1285 -0
  731. data/spec/mongo/server/description/features_spec.rb +250 -0
  732. data/spec/mongo/server/description_query_methods_spec.rb +291 -0
  733. data/spec/mongo/server/description_spec.rb +846 -0
  734. data/spec/mongo/server/monitor/app_metadata_spec.rb +25 -0
  735. data/spec/mongo/server/monitor/connection_spec.rb +175 -0
  736. data/spec/mongo/server/monitor_spec.rb +324 -0
  737. data/spec/mongo/server/round_trip_time_averager_spec.rb +48 -0
  738. data/spec/mongo/server_selector/nearest_spec.rb +338 -0
  739. data/spec/mongo/server_selector/primary_preferred_spec.rb +372 -0
  740. data/spec/mongo/server_selector/primary_spec.rb +181 -0
  741. data/spec/mongo/server_selector/secondary_preferred_spec.rb +350 -0
  742. data/spec/mongo/server_selector/secondary_spec.rb +278 -0
  743. data/spec/mongo/server_selector_spec.rb +615 -0
  744. data/spec/mongo/server_spec.rb +436 -0
  745. data/spec/mongo/session/server_session_spec.rb +62 -0
  746. data/spec/mongo/session/session_pool_spec.rb +240 -0
  747. data/spec/mongo/session_spec.rb +348 -0
  748. data/spec/mongo/session_transaction_spec.rb +221 -0
  749. data/spec/mongo/socket/ssl_spec.rb +867 -0
  750. data/spec/mongo/socket/tcp_spec.rb +17 -0
  751. data/spec/mongo/socket/unix_spec.rb +55 -0
  752. data/spec/mongo/socket_spec.rb +119 -0
  753. data/spec/mongo/srv/monitor_spec.rb +233 -0
  754. data/spec/mongo/srv/result_spec.rb +57 -0
  755. data/spec/mongo/timeout_spec.rb +42 -0
  756. data/spec/mongo/tls_context_hooks_spec.rb +40 -0
  757. data/spec/mongo/uri/srv_protocol_spec.rb +1108 -0
  758. data/spec/mongo/uri_option_parsing_spec.rb +592 -0
  759. data/spec/mongo/uri_spec.rb +1286 -0
  760. data/spec/mongo/utils_spec.rb +56 -0
  761. data/spec/mongo/write_concern/acknowledged_spec.rb +58 -0
  762. data/spec/mongo/write_concern/unacknowledged_spec.rb +29 -0
  763. data/spec/mongo/write_concern_spec.rb +227 -0
  764. data/spec/runners/auth.rb +140 -0
  765. data/spec/runners/change_streams/outcome.rb +45 -0
  766. data/spec/runners/change_streams/spec.rb +60 -0
  767. data/spec/runners/change_streams/test.rb +232 -0
  768. data/spec/runners/cmap/verifier.rb +48 -0
  769. data/spec/runners/cmap.rb +373 -0
  770. data/spec/runners/command_monitoring.rb +346 -0
  771. data/spec/runners/connection_string.rb +381 -0
  772. data/spec/runners/crud/context.rb +30 -0
  773. data/spec/runners/crud/operation.rb +469 -0
  774. data/spec/runners/crud/outcome.rb +56 -0
  775. data/spec/runners/crud/requirement.rb +133 -0
  776. data/spec/runners/crud/spec.rb +73 -0
  777. data/spec/runners/crud/test.rb +123 -0
  778. data/spec/runners/crud/test_base.rb +53 -0
  779. data/spec/runners/crud/verifier.rb +217 -0
  780. data/spec/runners/crud.rb +257 -0
  781. data/spec/runners/gridfs.rb +641 -0
  782. data/spec/runners/read_write_concern_document.rb +70 -0
  783. data/spec/runners/sdam/verifier.rb +112 -0
  784. data/spec/runners/sdam.rb +278 -0
  785. data/spec/runners/server_selection.rb +365 -0
  786. data/spec/runners/server_selection_rtt.rb +41 -0
  787. data/spec/runners/transactions/operation.rb +328 -0
  788. data/spec/runners/transactions/spec.rb +29 -0
  789. data/spec/runners/transactions/test.rb +326 -0
  790. data/spec/runners/transactions.rb +104 -0
  791. data/spec/runners/unified/assertions.rb +282 -0
  792. data/spec/runners/unified/change_stream_operations.rb +29 -0
  793. data/spec/runners/unified/crud_operations.rb +206 -0
  794. data/spec/runners/unified/ddl_operations.rb +106 -0
  795. data/spec/runners/unified/entity_map.rb +42 -0
  796. data/spec/runners/unified/error.rb +28 -0
  797. data/spec/runners/unified/event_subscriber.rb +104 -0
  798. data/spec/runners/unified/exceptions.rb +24 -0
  799. data/spec/runners/unified/grid_fs_operations.rb +58 -0
  800. data/spec/runners/unified/support_operations.rb +253 -0
  801. data/spec/runners/unified/test.rb +423 -0
  802. data/spec/runners/unified/test_group.rb +31 -0
  803. data/spec/runners/unified/using_hash.rb +34 -0
  804. data/spec/runners/unified.rb +99 -0
  805. data/spec/shared/LICENSE +20 -0
  806. data/spec/shared/bin/get-mongodb-download-url +17 -0
  807. data/spec/shared/bin/s3-copy +45 -0
  808. data/spec/shared/bin/s3-upload +69 -0
  809. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  810. data/spec/shared/lib/mrss/cluster_config.rb +226 -0
  811. data/spec/shared/lib/mrss/constraints.rb +379 -0
  812. data/spec/shared/lib/mrss/docker_runner.rb +271 -0
  813. data/spec/shared/lib/mrss/lite_constraints.rb +191 -0
  814. data/spec/shared/lib/mrss/server_version_registry.rb +115 -0
  815. data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
  816. data/spec/shared/lib/mrss/utils.rb +15 -0
  817. data/spec/shared/share/Dockerfile.erb +322 -0
  818. data/spec/shared/share/haproxy-1.conf +16 -0
  819. data/spec/shared/share/haproxy-2.conf +17 -0
  820. data/spec/shared/shlib/distro.sh +73 -0
  821. data/spec/shared/shlib/server.sh +317 -0
  822. data/spec/shared/shlib/set_env.sh +131 -0
  823. data/spec/solo/clean_exit_spec.rb +24 -0
  824. data/spec/spec_helper.rb +36 -0
  825. data/spec/spec_tests/auth_spec.rb +58 -0
  826. data/spec/spec_tests/change_streams_spec.rb +93 -0
  827. data/spec/spec_tests/change_streams_unified_spec.rb +13 -0
  828. data/spec/spec_tests/client_side_encryption_spec.rb +14 -0
  829. data/spec/spec_tests/cmap_spec.rb +109 -0
  830. data/spec/spec_tests/collection_management_spec.rb +13 -0
  831. data/spec/spec_tests/command_monitoring_spec.rb +71 -0
  832. data/spec/spec_tests/command_monitoring_unified_spec.rb +13 -0
  833. data/spec/spec_tests/connection_string_spec.rb +10 -0
  834. data/spec/spec_tests/crud_spec.rb +22 -0
  835. data/spec/spec_tests/crud_unified_spec.rb +13 -0
  836. data/spec/spec_tests/data/auth/connection-string.yml +366 -0
  837. data/spec/spec_tests/data/change_streams/change-streams-errors.yml +101 -0
  838. data/spec/spec_tests/data/change_streams/change-streams-resume-allowlist.yml +1173 -0
  839. data/spec/spec_tests/data/change_streams/change-streams-resume-errorLabels.yml +1105 -0
  840. data/spec/spec_tests/data/change_streams/change-streams.yml +535 -0
  841. data/spec/spec_tests/data/change_streams_unified/change-streams.yml +72 -0
  842. data/spec/spec_tests/data/client_side_encryption/aggregate.yml +134 -0
  843. data/spec/spec_tests/data/client_side_encryption/badQueries.yml +526 -0
  844. data/spec/spec_tests/data/client_side_encryption/badSchema.yml +73 -0
  845. data/spec/spec_tests/data/client_side_encryption/basic.yml +116 -0
  846. data/spec/spec_tests/data/client_side_encryption/bulk.yml +88 -0
  847. data/spec/spec_tests/data/client_side_encryption/bypassAutoEncryption.yml +100 -0
  848. data/spec/spec_tests/data/client_side_encryption/bypassedCommand.yml +42 -0
  849. data/spec/spec_tests/data/client_side_encryption/count.yml +61 -0
  850. data/spec/spec_tests/data/client_side_encryption/countDocuments.yml +59 -0
  851. data/spec/spec_tests/data/client_side_encryption/delete.yml +105 -0
  852. data/spec/spec_tests/data/client_side_encryption/distinct.yml +73 -0
  853. data/spec/spec_tests/data/client_side_encryption/explain.yml +64 -0
  854. data/spec/spec_tests/data/client_side_encryption/find.yml +119 -0
  855. data/spec/spec_tests/data/client_side_encryption/findOneAndDelete.yml +57 -0
  856. data/spec/spec_tests/data/client_side_encryption/findOneAndReplace.yml +57 -0
  857. data/spec/spec_tests/data/client_side_encryption/findOneAndUpdate.yml +57 -0
  858. data/spec/spec_tests/data/client_side_encryption/getMore.yml +68 -0
  859. data/spec/spec_tests/data/client_side_encryption/insert.yml +102 -0
  860. data/spec/spec_tests/data/client_side_encryption/keyAltName.yml +71 -0
  861. data/spec/spec_tests/data/client_side_encryption/localKMS.yml +54 -0
  862. data/spec/spec_tests/data/client_side_encryption/localSchema.yml +72 -0
  863. data/spec/spec_tests/data/client_side_encryption/malformedCiphertext.yml +69 -0
  864. data/spec/spec_tests/data/client_side_encryption/maxWireVersion.yml +20 -0
  865. data/spec/spec_tests/data/client_side_encryption/missingKey.yml +49 -0
  866. data/spec/spec_tests/data/client_side_encryption/replaceOne.yml +64 -0
  867. data/spec/spec_tests/data/client_side_encryption/types.yml +527 -0
  868. data/spec/spec_tests/data/client_side_encryption/unsupportedCommand.yml +25 -0
  869. data/spec/spec_tests/data/client_side_encryption/updateMany.yml +77 -0
  870. data/spec/spec_tests/data/client_side_encryption/updateOne.yml +171 -0
  871. data/spec/spec_tests/data/cmap/connection-must-have-id.yml +27 -0
  872. data/spec/spec_tests/data/cmap/connection-must-order-ids.yml +27 -0
  873. data/spec/spec_tests/data/cmap/pool-checkin-destroy-closed.yml +27 -0
  874. data/spec/spec_tests/data/cmap/pool-checkin-destroy-stale.yml +27 -0
  875. data/spec/spec_tests/data/cmap/pool-checkin-make-available.yml +24 -0
  876. data/spec/spec_tests/data/cmap/pool-checkin.yml +19 -0
  877. data/spec/spec_tests/data/cmap/pool-checkout-connection.yml +19 -0
  878. data/spec/spec_tests/data/cmap/pool-checkout-error-closed.yml +36 -0
  879. data/spec/spec_tests/data/cmap/pool-checkout-multiple.yml +37 -0
  880. data/spec/spec_tests/data/cmap/pool-checkout-no-idle.yml +35 -0
  881. data/spec/spec_tests/data/cmap/pool-checkout-no-stale.yml +33 -0
  882. data/spec/spec_tests/data/cmap/pool-close-destroy-conns.yml +28 -0
  883. data/spec/spec_tests/data/cmap/pool-close.yml +11 -0
  884. data/spec/spec_tests/data/cmap/pool-create-max-size.yml +71 -0
  885. data/spec/spec_tests/data/cmap/pool-create-min-size.yml +34 -0
  886. data/spec/spec_tests/data/cmap/pool-create-with-options.yml +21 -0
  887. data/spec/spec_tests/data/cmap/pool-create.yml +12 -0
  888. data/spec/spec_tests/data/cmap/wait-queue-fairness.yml +124 -0
  889. data/spec/spec_tests/data/cmap/wait-queue-timeout.yml +46 -0
  890. data/spec/spec_tests/data/collection_management/timeseries-collection.yml +129 -0
  891. data/spec/spec_tests/data/command_monitoring/bulkWrite.yml +49 -0
  892. data/spec/spec_tests/data/command_monitoring/command.yml +61 -0
  893. data/spec/spec_tests/data/command_monitoring/deleteMany.yml +55 -0
  894. data/spec/spec_tests/data/command_monitoring/deleteOne.yml +55 -0
  895. data/spec/spec_tests/data/command_monitoring/find.yml +266 -0
  896. data/spec/spec_tests/data/command_monitoring/insertMany.yml +75 -0
  897. data/spec/spec_tests/data/command_monitoring/insertOne.yml +51 -0
  898. data/spec/spec_tests/data/command_monitoring/unacknowledgedBulkWrite.yml +34 -0
  899. data/spec/spec_tests/data/command_monitoring/updateMany.yml +65 -0
  900. data/spec/spec_tests/data/command_monitoring/updateOne.yml +90 -0
  901. data/spec/spec_tests/data/command_monitoring_unified/redacted-commands.yml +340 -0
  902. data/spec/spec_tests/data/connection_string/invalid-uris.yml +261 -0
  903. data/spec/spec_tests/data/connection_string/valid-auth.yml +257 -0
  904. data/spec/spec_tests/data/connection_string/valid-db-with-dotted-name.yml +77 -0
  905. data/spec/spec_tests/data/connection_string/valid-host_identifiers.yml +121 -0
  906. data/spec/spec_tests/data/connection_string/valid-options.yml +17 -0
  907. data/spec/spec_tests/data/connection_string/valid-unix_socket-absolute.yml +197 -0
  908. data/spec/spec_tests/data/connection_string/valid-unix_socket-relative.yml +213 -0
  909. data/spec/spec_tests/data/connection_string/valid-warnings.yml +75 -0
  910. data/spec/spec_tests/data/crud/read/aggregate-collation.yml +17 -0
  911. data/spec/spec_tests/data/crud/read/aggregate-out.yml +43 -0
  912. data/spec/spec_tests/data/crud/read/aggregate.yml +21 -0
  913. data/spec/spec_tests/data/crud/read/count-collation.yml +25 -0
  914. data/spec/spec_tests/data/crud/read/count-empty.yml +29 -0
  915. data/spec/spec_tests/data/crud/read/count.yml +74 -0
  916. data/spec/spec_tests/data/crud/read/distinct-collation.yml +17 -0
  917. data/spec/spec_tests/data/crud/read/distinct.yml +32 -0
  918. data/spec/spec_tests/data/crud/read/find-collation.yml +15 -0
  919. data/spec/spec_tests/data/crud/read/find.yml +49 -0
  920. data/spec/spec_tests/data/crud/write/bulkWrite-arrayFilters.yml +45 -0
  921. data/spec/spec_tests/data/crud/write/bulkWrite-collation.yml +101 -0
  922. data/spec/spec_tests/data/crud/write/bulkWrite.yml +405 -0
  923. data/spec/spec_tests/data/crud/write/deleteMany-collation.yml +22 -0
  924. data/spec/spec_tests/data/crud/write/deleteMany.yml +35 -0
  925. data/spec/spec_tests/data/crud/write/deleteOne-collation.yml +22 -0
  926. data/spec/spec_tests/data/crud/write/deleteOne.yml +48 -0
  927. data/spec/spec_tests/data/crud/write/findOneAndDelete-collation.yml +23 -0
  928. data/spec/spec_tests/data/crud/write/findOneAndDelete.yml +53 -0
  929. data/spec/spec_tests/data/crud/write/findOneAndReplace-collation.yml +24 -0
  930. data/spec/spec_tests/data/crud/write/findOneAndReplace-upsert.yml +91 -0
  931. data/spec/spec_tests/data/crud/write/findOneAndReplace-upsert_pre_2.6.yml +88 -0
  932. data/spec/spec_tests/data/crud/write/findOneAndReplace.yml +113 -0
  933. data/spec/spec_tests/data/crud/write/findOneAndUpdate-arrayFilters.yml +69 -0
  934. data/spec/spec_tests/data/crud/write/findOneAndUpdate-collation.yml +27 -0
  935. data/spec/spec_tests/data/crud/write/findOneAndUpdate.yml +163 -0
  936. data/spec/spec_tests/data/crud/write/insertMany.yml +81 -0
  937. data/spec/spec_tests/data/crud/write/insertOne.yml +18 -0
  938. data/spec/spec_tests/data/crud/write/replaceOne-collation.yml +24 -0
  939. data/spec/spec_tests/data/crud/write/replaceOne-pre_2.6.yml +98 -0
  940. data/spec/spec_tests/data/crud/write/replaceOne-upsert.yml +48 -0
  941. data/spec/spec_tests/data/crud/write/replaceOne.yml +102 -0
  942. data/spec/spec_tests/data/crud/write/updateMany-arrayFilters.yml +66 -0
  943. data/spec/spec_tests/data/crud/write/updateMany-collation.yml +28 -0
  944. data/spec/spec_tests/data/crud/write/updateMany-pre_2.6.yml +86 -0
  945. data/spec/spec_tests/data/crud/write/updateMany.yml +87 -0
  946. data/spec/spec_tests/data/crud/write/updateOne-arrayFilters.yml +114 -0
  947. data/spec/spec_tests/data/crud/write/updateOne-collation.yml +25 -0
  948. data/spec/spec_tests/data/crud/write/updateOne-pre_2.6.yml +83 -0
  949. data/spec/spec_tests/data/crud/write/updateOne.yml +84 -0
  950. data/spec/spec_tests/data/crud_unified/estimatedDocumentCount.yml +267 -0
  951. data/spec/spec_tests/data/crud_unified/updateWithPipelines.yml +305 -0
  952. data/spec/spec_tests/data/crud_v2/aggregate-merge.yml +103 -0
  953. data/spec/spec_tests/data/crud_v2/aggregate-out-readConcern.yml +111 -0
  954. data/spec/spec_tests/data/crud_v2/bulkWrite-arrayFilters.yml +103 -0
  955. data/spec/spec_tests/data/crud_v2/bulkWrite-delete-hint-clientError.yml +63 -0
  956. data/spec/spec_tests/data/crud_v2/bulkWrite-delete-hint-serverError.yml +92 -0
  957. data/spec/spec_tests/data/crud_v2/bulkWrite-delete-hint.yml +103 -0
  958. data/spec/spec_tests/data/crud_v2/bulkWrite-update-hint-clientError.yml +90 -0
  959. data/spec/spec_tests/data/crud_v2/bulkWrite-update-hint-serverError.yml +147 -0
  960. data/spec/spec_tests/data/crud_v2/bulkWrite-update-hint.yml +164 -0
  961. data/spec/spec_tests/data/crud_v2/db-aggregate.yml +39 -0
  962. data/spec/spec_tests/data/crud_v2/deleteMany-hint-clientError.yml +43 -0
  963. data/spec/spec_tests/data/crud_v2/deleteMany-hint-serverError.yml +62 -0
  964. data/spec/spec_tests/data/crud_v2/deleteMany-hint.yml +58 -0
  965. data/spec/spec_tests/data/crud_v2/deleteOne-hint-clientError.yml +41 -0
  966. data/spec/spec_tests/data/crud_v2/deleteOne-hint-serverError.yml +60 -0
  967. data/spec/spec_tests/data/crud_v2/deleteOne-hint.yml +57 -0
  968. data/spec/spec_tests/data/crud_v2/find-allowdiskuse-clientError.yml +28 -0
  969. data/spec/spec_tests/data/crud_v2/find-allowdiskuse-serverError.yml +44 -0
  970. data/spec/spec_tests/data/crud_v2/find-allowdiskuse.yml +50 -0
  971. data/spec/spec_tests/data/crud_v2/findOneAndDelete-hint-clientError.yml +45 -0
  972. data/spec/spec_tests/data/crud_v2/findOneAndDelete-hint-serverError.yml +60 -0
  973. data/spec/spec_tests/data/crud_v2/findOneAndDelete-hint.yml +56 -0
  974. data/spec/spec_tests/data/crud_v2/findOneAndReplace-hint-clientError.yml +40 -0
  975. data/spec/spec_tests/data/crud_v2/findOneAndReplace-hint-serverError.yml +59 -0
  976. data/spec/spec_tests/data/crud_v2/findOneAndReplace-hint.yml +55 -0
  977. data/spec/spec_tests/data/crud_v2/findOneAndUpdate-hint-clientError.yml +40 -0
  978. data/spec/spec_tests/data/crud_v2/findOneAndUpdate-hint-serverError.yml +58 -0
  979. data/spec/spec_tests/data/crud_v2/findOneAndUpdate-hint.yml +55 -0
  980. data/spec/spec_tests/data/crud_v2/replaceOne-hint.yml +61 -0
  981. data/spec/spec_tests/data/crud_v2/unacknowledged-bulkWrite-delete-hint-clientError.yml +60 -0
  982. data/spec/spec_tests/data/crud_v2/unacknowledged-bulkWrite-update-hint-clientError.yml +88 -0
  983. data/spec/spec_tests/data/crud_v2/unacknowledged-deleteMany-hint-clientError.yml +40 -0
  984. data/spec/spec_tests/data/crud_v2/unacknowledged-deleteOne-hint-clientError.yml +38 -0
  985. data/spec/spec_tests/data/crud_v2/unacknowledged-findOneAndDelete-hint-clientError.yml +42 -0
  986. data/spec/spec_tests/data/crud_v2/unacknowledged-findOneAndReplace-hint-clientError.yml +40 -0
  987. data/spec/spec_tests/data/crud_v2/unacknowledged-findOneAndUpdate-hint-clientError.yml +40 -0
  988. data/spec/spec_tests/data/crud_v2/unacknowledged-replaceOne-hint-clientError.yml +40 -0
  989. data/spec/spec_tests/data/crud_v2/unacknowledged-updateMany-hint-clientError.yml +43 -0
  990. data/spec/spec_tests/data/crud_v2/unacknowledged-updateOne-hint-clientError.yml +40 -0
  991. data/spec/spec_tests/data/crud_v2/updateMany-hint-clientError.yml +45 -0
  992. data/spec/spec_tests/data/crud_v2/updateMany-hint-serverError.yml +66 -0
  993. data/spec/spec_tests/data/crud_v2/updateMany-hint.yml +65 -0
  994. data/spec/spec_tests/data/crud_v2/updateOne-hint-clientError.yml +43 -0
  995. data/spec/spec_tests/data/crud_v2/updateOne-hint-serverError.yml +62 -0
  996. data/spec/spec_tests/data/crud_v2/updateOne-hint.yml +61 -0
  997. data/spec/spec_tests/data/crud_v2/updateWithPipelines.yml +157 -0
  998. data/spec/spec_tests/data/dns_seedlist_discovery/direct-connection-false.yml +10 -0
  999. data/spec/spec_tests/data/dns_seedlist_discovery/direct-connection-true.yml +5 -0
  1000. data/spec/spec_tests/data/dns_seedlist_discovery/longer-parent-in-return.yml +11 -0
  1001. data/spec/spec_tests/data/dns_seedlist_discovery/misformatted-option.yml +5 -0
  1002. data/spec/spec_tests/data/dns_seedlist_discovery/no-results.yml +5 -0
  1003. data/spec/spec_tests/data/dns_seedlist_discovery/not-enough-parts.yml +5 -0
  1004. data/spec/spec_tests/data/dns_seedlist_discovery/one-result-default-port.yml +10 -0
  1005. data/spec/spec_tests/data/dns_seedlist_discovery/one-txt-record-multiple-strings.yml +10 -0
  1006. data/spec/spec_tests/data/dns_seedlist_discovery/one-txt-record.yml +11 -0
  1007. data/spec/spec_tests/data/dns_seedlist_discovery/parent-part-mismatch1.yml +5 -0
  1008. data/spec/spec_tests/data/dns_seedlist_discovery/parent-part-mismatch2.yml +5 -0
  1009. data/spec/spec_tests/data/dns_seedlist_discovery/parent-part-mismatch3.yml +5 -0
  1010. data/spec/spec_tests/data/dns_seedlist_discovery/parent-part-mismatch4.yml +5 -0
  1011. data/spec/spec_tests/data/dns_seedlist_discovery/parent-part-mismatch5.yml +5 -0
  1012. data/spec/spec_tests/data/dns_seedlist_discovery/returned-parent-too-short.yml +5 -0
  1013. data/spec/spec_tests/data/dns_seedlist_discovery/returned-parent-wrong.yml +5 -0
  1014. data/spec/spec_tests/data/dns_seedlist_discovery/two-results-default-port.yml +11 -0
  1015. data/spec/spec_tests/data/dns_seedlist_discovery/two-results-nonstandard-port.yml +11 -0
  1016. data/spec/spec_tests/data/dns_seedlist_discovery/two-txt-records.yml +5 -0
  1017. data/spec/spec_tests/data/dns_seedlist_discovery/txt-record-not-allowed-option.yml +5 -0
  1018. data/spec/spec_tests/data/dns_seedlist_discovery/txt-record-with-overridden-ssl-option.yml +11 -0
  1019. data/spec/spec_tests/data/dns_seedlist_discovery/txt-record-with-overridden-uri-option.yml +11 -0
  1020. data/spec/spec_tests/data/dns_seedlist_discovery/txt-record-with-unallowed-option.yml +5 -0
  1021. data/spec/spec_tests/data/dns_seedlist_discovery/uri-with-port.yml +5 -0
  1022. data/spec/spec_tests/data/dns_seedlist_discovery/uri-with-two-hosts.yml +5 -0
  1023. data/spec/spec_tests/data/gridfs/delete.yml +123 -0
  1024. data/spec/spec_tests/data/gridfs/download.yml +192 -0
  1025. data/spec/spec_tests/data/gridfs/download_by_name.yml +113 -0
  1026. data/spec/spec_tests/data/gridfs/upload.yml +158 -0
  1027. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/DefaultNoMaxStaleness.yml +26 -0
  1028. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/Incompatible.yml +25 -0
  1029. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.yml +33 -0
  1030. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/MaxStalenessTooSmall.yml +15 -0
  1031. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/Nearest.yml +33 -0
  1032. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/Nearest2.yml +33 -0
  1033. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/NoKnownServers.yml +16 -0
  1034. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.yml +27 -0
  1035. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.yml +36 -0
  1036. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/Secondary.yml +51 -0
  1037. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.yml +26 -0
  1038. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.yml +51 -0
  1039. data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/ZeroMaxStaleness.yml +23 -0
  1040. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/DefaultNoMaxStaleness.yml +26 -0
  1041. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/Incompatible.yml +25 -0
  1042. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.yml +35 -0
  1043. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/LongHeartbeat.yml +29 -0
  1044. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/LongHeartbeat2.yml +25 -0
  1045. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.yml +26 -0
  1046. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.yml +23 -0
  1047. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/Nearest.yml +33 -0
  1048. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/Nearest2.yml +33 -0
  1049. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/Nearest_tags.yml +36 -0
  1050. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.yml +27 -0
  1051. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.yml +27 -0
  1052. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.yml +26 -0
  1053. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.yml +59 -0
  1054. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.yml +43 -0
  1055. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/Secondary_tags.yml +59 -0
  1056. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.yml +43 -0
  1057. data/spec/spec_tests/data/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.yml +23 -0
  1058. data/spec/spec_tests/data/max_staleness/Sharded/Incompatible.yml +25 -0
  1059. data/spec/spec_tests/data/max_staleness/Sharded/SmallMaxStaleness.yml +28 -0
  1060. data/spec/spec_tests/data/max_staleness/Single/Incompatible.yml +18 -0
  1061. data/spec/spec_tests/data/max_staleness/Single/SmallMaxStaleness.yml +20 -0
  1062. data/spec/spec_tests/data/max_staleness/Unknown/SmallMaxStaleness.yml +15 -0
  1063. data/spec/spec_tests/data/read_write_concern/connection-string/read-concern.yml +32 -0
  1064. data/spec/spec_tests/data/read_write_concern/connection-string/write-concern.yml +79 -0
  1065. data/spec/spec_tests/data/read_write_concern/document/read-concern.yml +37 -0
  1066. data/spec/spec_tests/data/read_write_concern/document/write-concern.yml +100 -0
  1067. data/spec/spec_tests/data/read_write_concern/operation/default-write-concern-2.6.yml +215 -0
  1068. data/spec/spec_tests/data/read_write_concern/operation/default-write-concern-3.2.yml +58 -0
  1069. data/spec/spec_tests/data/read_write_concern/operation/default-write-concern-3.4.yml +95 -0
  1070. data/spec/spec_tests/data/read_write_concern/operation/default-write-concern-4.2.yml +36 -0
  1071. data/spec/spec_tests/data/retryable_reads/aggregate-merge.yml +39 -0
  1072. data/spec/spec_tests/data/retryable_reads/aggregate-serverErrors.yml +157 -0
  1073. data/spec/spec_tests/data/retryable_reads/aggregate.yml +87 -0
  1074. data/spec/spec_tests/data/retryable_reads/changeStreams-client.watch-serverErrors.yml +150 -0
  1075. data/spec/spec_tests/data/retryable_reads/changeStreams-client.watch.yml +62 -0
  1076. data/spec/spec_tests/data/retryable_reads/changeStreams-db.coll.watch-serverErrors.yml +150 -0
  1077. data/spec/spec_tests/data/retryable_reads/changeStreams-db.coll.watch.yml +66 -0
  1078. data/spec/spec_tests/data/retryable_reads/changeStreams-db.watch-serverErrors.yml +154 -0
  1079. data/spec/spec_tests/data/retryable_reads/changeStreams-db.watch.yml +62 -0
  1080. data/spec/spec_tests/data/retryable_reads/count-serverErrors.yml +150 -0
  1081. data/spec/spec_tests/data/retryable_reads/count.yml +64 -0
  1082. data/spec/spec_tests/data/retryable_reads/countDocuments-serverErrors.yml +150 -0
  1083. data/spec/spec_tests/data/retryable_reads/countDocuments.yml +64 -0
  1084. data/spec/spec_tests/data/retryable_reads/distinct-serverErrors.yml +156 -0
  1085. data/spec/spec_tests/data/retryable_reads/distinct.yml +71 -0
  1086. data/spec/spec_tests/data/retryable_reads/estimatedDocumentCount-4.9.yml +60 -0
  1087. data/spec/spec_tests/data/retryable_reads/estimatedDocumentCount-pre4.9.yml +64 -0
  1088. data/spec/spec_tests/data/retryable_reads/estimatedDocumentCount-serverErrors-4.9.yml +146 -0
  1089. data/spec/spec_tests/data/retryable_reads/estimatedDocumentCount-serverErrors-pre4.9.yml +150 -0
  1090. data/spec/spec_tests/data/retryable_reads/find-serverErrors.yml +160 -0
  1091. data/spec/spec_tests/data/retryable_reads/find.yml +86 -0
  1092. data/spec/spec_tests/data/retryable_reads/findOne-serverErrors.yml +154 -0
  1093. data/spec/spec_tests/data/retryable_reads/findOne.yml +68 -0
  1094. data/spec/spec_tests/data/retryable_reads/gridfs-download-serverErrors.yml +173 -0
  1095. data/spec/spec_tests/data/retryable_reads/gridfs-download.yml +79 -0
  1096. data/spec/spec_tests/data/retryable_reads/gridfs-downloadByName-serverErrors.yml +174 -0
  1097. data/spec/spec_tests/data/retryable_reads/gridfs-downloadByName.yml +79 -0
  1098. data/spec/spec_tests/data/retryable_reads/listCollectionNames-serverErrors.yml +143 -0
  1099. data/spec/spec_tests/data/retryable_reads/listCollectionNames.yml +59 -0
  1100. data/spec/spec_tests/data/retryable_reads/listCollectionObjects-serverErrors.yml +144 -0
  1101. data/spec/spec_tests/data/retryable_reads/listCollectionObjects.yml +59 -0
  1102. data/spec/spec_tests/data/retryable_reads/listCollections-serverErrors.yml +143 -0
  1103. data/spec/spec_tests/data/retryable_reads/listCollections.yml +59 -0
  1104. data/spec/spec_tests/data/retryable_reads/listDatabaseNames-serverErrors.yml +143 -0
  1105. data/spec/spec_tests/data/retryable_reads/listDatabaseNames.yml +59 -0
  1106. data/spec/spec_tests/data/retryable_reads/listDatabaseObjects-serverErrors.yml +144 -0
  1107. data/spec/spec_tests/data/retryable_reads/listDatabaseObjects.yml +59 -0
  1108. data/spec/spec_tests/data/retryable_reads/listDatabases-serverErrors.yml +144 -0
  1109. data/spec/spec_tests/data/retryable_reads/listDatabases.yml +59 -0
  1110. data/spec/spec_tests/data/retryable_reads/listIndexNames-serverErrors.yml +144 -0
  1111. data/spec/spec_tests/data/retryable_reads/listIndexNames.yml +60 -0
  1112. data/spec/spec_tests/data/retryable_reads/listIndexes-serverErrors.yml +145 -0
  1113. data/spec/spec_tests/data/retryable_reads/listIndexes.yml +60 -0
  1114. data/spec/spec_tests/data/retryable_reads/mapReduce.yml +60 -0
  1115. data/spec/spec_tests/data/retryable_writes/bulkWrite-errorLabels.yml +77 -0
  1116. data/spec/spec_tests/data/retryable_writes/bulkWrite-serverErrors.yml +130 -0
  1117. data/spec/spec_tests/data/retryable_writes/bulkWrite.yml +402 -0
  1118. data/spec/spec_tests/data/retryable_writes/deleteMany.yml +22 -0
  1119. data/spec/spec_tests/data/retryable_writes/deleteOne-errorLabels.yml +48 -0
  1120. data/spec/spec_tests/data/retryable_writes/deleteOne-serverErrors.yml +73 -0
  1121. data/spec/spec_tests/data/retryable_writes/deleteOne.yml +57 -0
  1122. data/spec/spec_tests/data/retryable_writes/findOneAndDelete-errorLabels.yml +49 -0
  1123. data/spec/spec_tests/data/retryable_writes/findOneAndDelete-serverErrors.yml +74 -0
  1124. data/spec/spec_tests/data/retryable_writes/findOneAndDelete.yml +58 -0
  1125. data/spec/spec_tests/data/retryable_writes/findOneAndReplace-errorLabels.yml +52 -0
  1126. data/spec/spec_tests/data/retryable_writes/findOneAndReplace-serverErrors.yml +80 -0
  1127. data/spec/spec_tests/data/retryable_writes/findOneAndReplace.yml +63 -0
  1128. data/spec/spec_tests/data/retryable_writes/findOneAndUpdate-errorLabels.yml +52 -0
  1129. data/spec/spec_tests/data/retryable_writes/findOneAndUpdate-serverErrors.yml +79 -0
  1130. data/spec/spec_tests/data/retryable_writes/findOneAndUpdate.yml +62 -0
  1131. data/spec/spec_tests/data/retryable_writes/insertMany-errorLabels.yml +54 -0
  1132. data/spec/spec_tests/data/retryable_writes/insertMany-serverErrors.yml +84 -0
  1133. data/spec/spec_tests/data/retryable_writes/insertMany.yml +74 -0
  1134. data/spec/spec_tests/data/retryable_writes/insertOne-errorLabels.yml +44 -0
  1135. data/spec/spec_tests/data/retryable_writes/insertOne-serverErrors.yml +527 -0
  1136. data/spec/spec_tests/data/retryable_writes/insertOne.yml +61 -0
  1137. data/spec/spec_tests/data/retryable_writes/replaceOne-errorLabels.yml +53 -0
  1138. data/spec/spec_tests/data/retryable_writes/replaceOne-serverErrors.yml +82 -0
  1139. data/spec/spec_tests/data/retryable_writes/replaceOne.yml +66 -0
  1140. data/spec/spec_tests/data/retryable_writes/updateMany.yml +27 -0
  1141. data/spec/spec_tests/data/retryable_writes/updateOne-errorLabels.yml +53 -0
  1142. data/spec/spec_tests/data/retryable_writes/updateOne-serverErrors.yml +82 -0
  1143. data/spec/spec_tests/data/retryable_writes/updateOne.yml +129 -0
  1144. data/spec/spec_tests/data/sdam/errors/error_handling_handshake.yml +55 -0
  1145. data/spec/spec_tests/data/sdam/errors/non-stale-network-error.yml +47 -0
  1146. data/spec/spec_tests/data/sdam/errors/non-stale-network-timeout-error.yml +38 -0
  1147. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-greater-InterruptedAtShutdown.yml +61 -0
  1148. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-greater-InterruptedDueToReplStateChange.yml +61 -0
  1149. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-greater-LegacyNotPrimary.yml +61 -0
  1150. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-greater-NotPrimaryNoSecondaryOk.yml +61 -0
  1151. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-greater-NotPrimaryOrSecondary.yml +61 -0
  1152. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-greater-NotWritablePrimary.yml +61 -0
  1153. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-greater-PrimarySteppedDown.yml +61 -0
  1154. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-greater-ShutdownInProgress.yml +61 -0
  1155. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-missing-InterruptedAtShutdown.yml +52 -0
  1156. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-missing-InterruptedDueToReplStateChange.yml +52 -0
  1157. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-missing-LegacyNotPrimary.yml +52 -0
  1158. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-missing-NotPrimaryNoSecondaryOk.yml +52 -0
  1159. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-missing-NotPrimaryOrSecondary.yml +52 -0
  1160. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-missing-NotWritablePrimary.yml +52 -0
  1161. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-missing-PrimarySteppedDown.yml +52 -0
  1162. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-missing-ShutdownInProgress.yml +52 -0
  1163. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-proccessId-changed-InterruptedAtShutdown.yml +61 -0
  1164. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-proccessId-changed-InterruptedDueToReplStateChange.yml +61 -0
  1165. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-proccessId-changed-LegacyNotPrimary.yml +61 -0
  1166. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-proccessId-changed-NotPrimaryNoSecondaryOk.yml +61 -0
  1167. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-proccessId-changed-NotPrimaryOrSecondary.yml +61 -0
  1168. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-proccessId-changed-NotWritablePrimary.yml +61 -0
  1169. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-proccessId-changed-PrimarySteppedDown.yml +61 -0
  1170. data/spec/spec_tests/data/sdam/errors/non-stale-topologyVersion-proccessId-changed-ShutdownInProgress.yml +61 -0
  1171. data/spec/spec_tests/data/sdam/errors/post-42-InterruptedAtShutdown.yml +47 -0
  1172. data/spec/spec_tests/data/sdam/errors/post-42-InterruptedDueToReplStateChange.yml +47 -0
  1173. data/spec/spec_tests/data/sdam/errors/post-42-LegacyNotPrimary.yml +47 -0
  1174. data/spec/spec_tests/data/sdam/errors/post-42-NotPrimaryNoSecondaryOk.yml +47 -0
  1175. data/spec/spec_tests/data/sdam/errors/post-42-NotPrimaryOrSecondary.yml +47 -0
  1176. data/spec/spec_tests/data/sdam/errors/post-42-NotWritablePrimary.yml +47 -0
  1177. data/spec/spec_tests/data/sdam/errors/post-42-PrimarySteppedDown.yml +47 -0
  1178. data/spec/spec_tests/data/sdam/errors/post-42-ShutdownInProgress.yml +47 -0
  1179. data/spec/spec_tests/data/sdam/errors/pre-42-InterruptedAtShutdown.yml +47 -0
  1180. data/spec/spec_tests/data/sdam/errors/pre-42-InterruptedDueToReplStateChange.yml +47 -0
  1181. data/spec/spec_tests/data/sdam/errors/pre-42-LegacyNotPrimary.yml +47 -0
  1182. data/spec/spec_tests/data/sdam/errors/pre-42-NotPrimaryNoSecondaryOk.yml +47 -0
  1183. data/spec/spec_tests/data/sdam/errors/pre-42-NotPrimaryOrSecondary.yml +47 -0
  1184. data/spec/spec_tests/data/sdam/errors/pre-42-NotWritablePrimary.yml +47 -0
  1185. data/spec/spec_tests/data/sdam/errors/pre-42-PrimarySteppedDown.yml +47 -0
  1186. data/spec/spec_tests/data/sdam/errors/pre-42-ShutdownInProgress.yml +47 -0
  1187. data/spec/spec_tests/data/sdam/errors/prefer-error-code.yml +54 -0
  1188. data/spec/spec_tests/data/sdam/errors/stale-generation-InterruptedAtShutdown.yml +91 -0
  1189. data/spec/spec_tests/data/sdam/errors/stale-generation-InterruptedDueToReplStateChange.yml +91 -0
  1190. data/spec/spec_tests/data/sdam/errors/stale-generation-NotPrimaryNoSecondaryOk.yml +91 -0
  1191. data/spec/spec_tests/data/sdam/errors/stale-generation-NotPrimaryOrSecondary.yml +91 -0
  1192. data/spec/spec_tests/data/sdam/errors/stale-generation-NotWritablePrimary.yml +91 -0
  1193. data/spec/spec_tests/data/sdam/errors/stale-generation-PrimarySteppedDown.yml +91 -0
  1194. data/spec/spec_tests/data/sdam/errors/stale-generation-ShutdownInProgress.yml +91 -0
  1195. data/spec/spec_tests/data/sdam/errors/stale-generation-afterHandshakeCompletes-InterruptedAtShutdown.yml +91 -0
  1196. data/spec/spec_tests/data/sdam/errors/stale-generation-afterHandshakeCompletes-InterruptedDueToReplStateChange.yml +91 -0
  1197. data/spec/spec_tests/data/sdam/errors/stale-generation-afterHandshakeCompletes-LegacyNotPrimary.yml +91 -0
  1198. data/spec/spec_tests/data/sdam/errors/stale-generation-afterHandshakeCompletes-NotPrimaryNoSecondaryOk.yml +91 -0
  1199. data/spec/spec_tests/data/sdam/errors/stale-generation-afterHandshakeCompletes-NotPrimaryOrSecondary.yml +91 -0
  1200. data/spec/spec_tests/data/sdam/errors/stale-generation-afterHandshakeCompletes-NotWritablePrimary.yml +91 -0
  1201. data/spec/spec_tests/data/sdam/errors/stale-generation-afterHandshakeCompletes-PrimarySteppedDown.yml +91 -0
  1202. data/spec/spec_tests/data/sdam/errors/stale-generation-afterHandshakeCompletes-ShutdownInProgress.yml +91 -0
  1203. data/spec/spec_tests/data/sdam/errors/stale-generation-afterHandshakeCompletes-network.yml +82 -0
  1204. data/spec/spec_tests/data/sdam/errors/stale-generation-afterHandshakeCompletes-timeout.yml +82 -0
  1205. data/spec/spec_tests/data/sdam/errors/stale-generation-beforeHandshakeCompletes-InterruptedAtShutdown.yml +91 -0
  1206. data/spec/spec_tests/data/sdam/errors/stale-generation-beforeHandshakeCompletes-InterruptedDueToReplStateChange.yml +91 -0
  1207. data/spec/spec_tests/data/sdam/errors/stale-generation-beforeHandshakeCompletes-LegacyNotPrimary.yml +91 -0
  1208. data/spec/spec_tests/data/sdam/errors/stale-generation-beforeHandshakeCompletes-NotPrimaryNoSecondaryOk.yml +91 -0
  1209. data/spec/spec_tests/data/sdam/errors/stale-generation-beforeHandshakeCompletes-NotPrimaryOrSecondary.yml +91 -0
  1210. data/spec/spec_tests/data/sdam/errors/stale-generation-beforeHandshakeCompletes-NotWritablePrimary.yml +91 -0
  1211. data/spec/spec_tests/data/sdam/errors/stale-generation-beforeHandshakeCompletes-PrimarySteppedDown.yml +91 -0
  1212. data/spec/spec_tests/data/sdam/errors/stale-generation-beforeHandshakeCompletes-ShutdownInProgress.yml +91 -0
  1213. data/spec/spec_tests/data/sdam/errors/stale-generation-beforeHandshakeCompletes-network.yml +82 -0
  1214. data/spec/spec_tests/data/sdam/errors/stale-generation-beforeHandshakeCompletes-timeout.yml +82 -0
  1215. data/spec/spec_tests/data/sdam/errors/stale-topologyVersion-InterruptedAtShutdown.yml +65 -0
  1216. data/spec/spec_tests/data/sdam/errors/stale-topologyVersion-InterruptedDueToReplStateChange.yml +65 -0
  1217. data/spec/spec_tests/data/sdam/errors/stale-topologyVersion-LegacyNotPrimary.yml +65 -0
  1218. data/spec/spec_tests/data/sdam/errors/stale-topologyVersion-NotPrimaryNoSecondaryOk.yml +65 -0
  1219. data/spec/spec_tests/data/sdam/errors/stale-topologyVersion-NotPrimaryOrSecondary.yml +65 -0
  1220. data/spec/spec_tests/data/sdam/errors/stale-topologyVersion-NotWritablePrimary.yml +65 -0
  1221. data/spec/spec_tests/data/sdam/errors/stale-topologyVersion-PrimarySteppedDown.yml +65 -0
  1222. data/spec/spec_tests/data/sdam/errors/stale-topologyVersion-ShutdownInProgress.yml +65 -0
  1223. data/spec/spec_tests/data/sdam/errors/write_errors_ignored.yml +42 -0
  1224. data/spec/spec_tests/data/sdam/rs/compatible.yml +45 -0
  1225. data/spec/spec_tests/data/sdam/rs/compatible_unknown.yml +34 -0
  1226. data/spec/spec_tests/data/sdam/rs/discover_arbiters.yml +44 -0
  1227. data/spec/spec_tests/data/sdam/rs/discover_arbiters_replicaset.yml +44 -0
  1228. data/spec/spec_tests/data/sdam/rs/discover_ghost.yml +36 -0
  1229. data/spec/spec_tests/data/sdam/rs/discover_ghost_replicaset.yml +42 -0
  1230. data/spec/spec_tests/data/sdam/rs/discover_hidden.yml +51 -0
  1231. data/spec/spec_tests/data/sdam/rs/discover_hidden_replicaset.yml +51 -0
  1232. data/spec/spec_tests/data/sdam/rs/discover_passives.yml +83 -0
  1233. data/spec/spec_tests/data/sdam/rs/discover_passives_replicaset.yml +83 -0
  1234. data/spec/spec_tests/data/sdam/rs/discover_primary.yml +43 -0
  1235. data/spec/spec_tests/data/sdam/rs/discover_primary_replicaset.yml +43 -0
  1236. data/spec/spec_tests/data/sdam/rs/discover_rsother.yml +50 -0
  1237. data/spec/spec_tests/data/sdam/rs/discover_rsother_replicaset.yml +68 -0
  1238. data/spec/spec_tests/data/sdam/rs/discover_secondary.yml +44 -0
  1239. data/spec/spec_tests/data/sdam/rs/discover_secondary_replicaset.yml +44 -0
  1240. data/spec/spec_tests/data/sdam/rs/discovery.yml +207 -0
  1241. data/spec/spec_tests/data/sdam/rs/equal_electionids.yml +57 -0
  1242. data/spec/spec_tests/data/sdam/rs/hosts_differ_from_seeds.yml +37 -0
  1243. data/spec/spec_tests/data/sdam/rs/incompatible_arbiter.yml +36 -0
  1244. data/spec/spec_tests/data/sdam/rs/incompatible_ghost.yml +34 -0
  1245. data/spec/spec_tests/data/sdam/rs/incompatible_other.yml +36 -0
  1246. data/spec/spec_tests/data/sdam/rs/ls_timeout.yml +249 -0
  1247. data/spec/spec_tests/data/sdam/rs/member_reconfig.yml +74 -0
  1248. data/spec/spec_tests/data/sdam/rs/member_standalone.yml +66 -0
  1249. data/spec/spec_tests/data/sdam/rs/new_primary.yml +80 -0
  1250. data/spec/spec_tests/data/sdam/rs/new_primary_new_electionid.yml +119 -0
  1251. data/spec/spec_tests/data/sdam/rs/new_primary_new_setversion.yml +119 -0
  1252. data/spec/spec_tests/data/sdam/rs/new_primary_wrong_set_name.yml +77 -0
  1253. data/spec/spec_tests/data/sdam/rs/non_rs_member.yml +33 -0
  1254. data/spec/spec_tests/data/sdam/rs/normalize_case.yml +52 -0
  1255. data/spec/spec_tests/data/sdam/rs/normalize_case_me.yml +102 -0
  1256. data/spec/spec_tests/data/sdam/rs/null_election_id.yml +175 -0
  1257. data/spec/spec_tests/data/sdam/rs/primary_becomes_ghost.yml +65 -0
  1258. data/spec/spec_tests/data/sdam/rs/primary_becomes_mongos.yml +58 -0
  1259. data/spec/spec_tests/data/sdam/rs/primary_becomes_standalone.yml +55 -0
  1260. data/spec/spec_tests/data/sdam/rs/primary_changes_set_name.yml +63 -0
  1261. data/spec/spec_tests/data/sdam/rs/primary_disconnect.yml +59 -0
  1262. data/spec/spec_tests/data/sdam/rs/primary_disconnect_electionid.yml +189 -0
  1263. data/spec/spec_tests/data/sdam/rs/primary_disconnect_setversion.yml +189 -0
  1264. data/spec/spec_tests/data/sdam/rs/primary_hint_from_secondary_with_mismatched_me.yml +64 -0
  1265. data/spec/spec_tests/data/sdam/rs/primary_mismatched_me.yml +27 -0
  1266. data/spec/spec_tests/data/sdam/rs/primary_mismatched_me_not_removed.yml +75 -0
  1267. data/spec/spec_tests/data/sdam/rs/primary_reports_new_member.yml +175 -0
  1268. data/spec/spec_tests/data/sdam/rs/primary_to_no_primary_mismatched_me.yml +81 -0
  1269. data/spec/spec_tests/data/sdam/rs/primary_wrong_set_name.yml +30 -0
  1270. data/spec/spec_tests/data/sdam/rs/repeated.yml +105 -0
  1271. data/spec/spec_tests/data/sdam/rs/replicaset_rsnp.yml +21 -0
  1272. data/spec/spec_tests/data/sdam/rs/response_from_removed.yml +69 -0
  1273. data/spec/spec_tests/data/sdam/rs/ruby_primary_address_change.yml +31 -0
  1274. data/spec/spec_tests/data/sdam/rs/ruby_secondary_wrong_set_name_with_primary_second.yml +73 -0
  1275. data/spec/spec_tests/data/sdam/rs/sec_not_auth.yml +55 -0
  1276. data/spec/spec_tests/data/sdam/rs/secondary_ignore_ok_0.yml +87 -0
  1277. data/spec/spec_tests/data/sdam/rs/secondary_mismatched_me.yml +28 -0
  1278. data/spec/spec_tests/data/sdam/rs/secondary_wrong_set_name.yml +31 -0
  1279. data/spec/spec_tests/data/sdam/rs/secondary_wrong_set_name_with_primary.yml +75 -0
  1280. data/spec/spec_tests/data/sdam/rs/setversion_without_electionid.yml +79 -0
  1281. data/spec/spec_tests/data/sdam/rs/stepdown_change_set_name.yml +65 -0
  1282. data/spec/spec_tests/data/sdam/rs/too_new.yml +45 -0
  1283. data/spec/spec_tests/data/sdam/rs/too_old.yml +41 -0
  1284. data/spec/spec_tests/data/sdam/rs/topology_version_equal.yml +68 -0
  1285. data/spec/spec_tests/data/sdam/rs/topology_version_greater.yml +194 -0
  1286. data/spec/spec_tests/data/sdam/rs/topology_version_less.yml +64 -0
  1287. data/spec/spec_tests/data/sdam/rs/unexpected_mongos.yml +29 -0
  1288. data/spec/spec_tests/data/sdam/rs/use_setversion_without_electionid.yml +117 -0
  1289. data/spec/spec_tests/data/sdam/rs/wrong_set_name.yml +38 -0
  1290. data/spec/spec_tests/data/sdam/sharded/compatible.yml +40 -0
  1291. data/spec/spec_tests/data/sdam/sharded/discover_single_mongos.yml +24 -0
  1292. data/spec/spec_tests/data/sdam/sharded/ls_timeout_mongos.yml +101 -0
  1293. data/spec/spec_tests/data/sdam/sharded/mongos_disconnect.yml +113 -0
  1294. data/spec/spec_tests/data/sdam/sharded/multiple_mongoses.yml +52 -0
  1295. data/spec/spec_tests/data/sdam/sharded/non_mongos_removed.yml +47 -0
  1296. data/spec/spec_tests/data/sdam/sharded/normalize_uri_case.yml +32 -0
  1297. data/spec/spec_tests/data/sdam/sharded/ruby_primary_different_address.yml +21 -0
  1298. data/spec/spec_tests/data/sdam/sharded/ruby_primary_mismatched_me.yml +22 -0
  1299. data/spec/spec_tests/data/sdam/sharded/too_new.yml +38 -0
  1300. data/spec/spec_tests/data/sdam/sharded/too_old.yml +38 -0
  1301. data/spec/spec_tests/data/sdam/single/compatible.yml +27 -0
  1302. data/spec/spec_tests/data/sdam/single/direct_connection_external_ip.yml +37 -0
  1303. data/spec/spec_tests/data/sdam/single/direct_connection_mongos.yml +36 -0
  1304. data/spec/spec_tests/data/sdam/single/direct_connection_replicaset.yml +23 -0
  1305. data/spec/spec_tests/data/sdam/single/direct_connection_rsarbiter.yml +38 -0
  1306. data/spec/spec_tests/data/sdam/single/direct_connection_rsprimary.yml +37 -0
  1307. data/spec/spec_tests/data/sdam/single/direct_connection_rssecondary.yml +38 -0
  1308. data/spec/spec_tests/data/sdam/single/direct_connection_standalone.yml +35 -0
  1309. data/spec/spec_tests/data/sdam/single/direct_connection_unavailable_seed.yml +28 -0
  1310. data/spec/spec_tests/data/sdam/single/direct_connection_wrong_set_name.yml +40 -0
  1311. data/spec/spec_tests/data/sdam/single/discover_standalone.yml +35 -0
  1312. data/spec/spec_tests/data/sdam/single/discover_unavailable_seed.yml +28 -0
  1313. data/spec/spec_tests/data/sdam/single/ls_timeout_standalone.yml +36 -0
  1314. data/spec/spec_tests/data/sdam/single/not_ok_response.yml +44 -0
  1315. data/spec/spec_tests/data/sdam/single/ruby_primary_different_address.yml +24 -0
  1316. data/spec/spec_tests/data/sdam/single/ruby_primary_mismatched_me.yml +25 -0
  1317. data/spec/spec_tests/data/sdam/single/standalone_removed.yml +35 -0
  1318. data/spec/spec_tests/data/sdam/single/standalone_using_legacy_hello.yml +34 -0
  1319. data/spec/spec_tests/data/sdam/single/too_new.yml +27 -0
  1320. data/spec/spec_tests/data/sdam/single/too_old.yml +25 -0
  1321. data/spec/spec_tests/data/sdam/single/too_old_then_upgraded.yml +48 -0
  1322. data/spec/spec_tests/data/sdam_integration/cancel-server-check.yml +96 -0
  1323. data/spec/spec_tests/data/sdam_integration/connectTimeoutMS.yml +88 -0
  1324. data/spec/spec_tests/data/sdam_integration/find-network-error.yml +83 -0
  1325. data/spec/spec_tests/data/sdam_integration/find-shutdown-error.yml +116 -0
  1326. data/spec/spec_tests/data/sdam_integration/hello-command-error.yml +158 -0
  1327. data/spec/spec_tests/data/sdam_integration/hello-network-error.yml +156 -0
  1328. data/spec/spec_tests/data/sdam_integration/hello-timeout.yml +223 -0
  1329. data/spec/spec_tests/data/sdam_integration/insert-network-error.yml +86 -0
  1330. data/spec/spec_tests/data/sdam_integration/insert-shutdown-error.yml +115 -0
  1331. data/spec/spec_tests/data/sdam_integration/rediscover-quickly-after-step-down.yml +98 -0
  1332. data/spec/spec_tests/data/sdam_monitoring/discovered_standalone.yml +70 -0
  1333. data/spec/spec_tests/data/sdam_monitoring/replica_set_other_chain.yml +222 -0
  1334. data/spec/spec_tests/data/sdam_monitoring/replica_set_other_change.yml +225 -0
  1335. data/spec/spec_tests/data/sdam_monitoring/replica_set_primary_address_change.yml +251 -0
  1336. data/spec/spec_tests/data/sdam_monitoring/replica_set_with_me_mismatch.yml +111 -0
  1337. data/spec/spec_tests/data/sdam_monitoring/replica_set_with_no_primary.yml +113 -0
  1338. data/spec/spec_tests/data/sdam_monitoring/replica_set_with_primary.yml +112 -0
  1339. data/spec/spec_tests/data/sdam_monitoring/replica_set_with_primary_and_secondary.yml +198 -0
  1340. data/spec/spec_tests/data/sdam_monitoring/replica_set_with_primary_removal.yml +175 -0
  1341. data/spec/spec_tests/data/sdam_monitoring/replica_set_with_removal.yml +111 -0
  1342. data/spec/spec_tests/data/sdam_monitoring/replica_set_with_second_seed_removal.yml +106 -0
  1343. data/spec/spec_tests/data/sdam_monitoring/required_replica_set.yml +108 -0
  1344. data/spec/spec_tests/data/sdam_monitoring/standalone.yml +70 -0
  1345. data/spec/spec_tests/data/sdam_monitoring/standalone_repeated.yml +86 -0
  1346. data/spec/spec_tests/data/sdam_monitoring/standalone_suppress_equal_description_changes.yml +73 -0
  1347. data/spec/spec_tests/data/sdam_monitoring/standalone_to_rs_with_me_mismatch.yml +90 -0
  1348. data/spec/spec_tests/data/server_selection/ReplicaSetNoPrimary/read/Nearest.yml +25 -0
  1349. data/spec/spec_tests/data/server_selection/ReplicaSetNoPrimary/read/Nearest_multiple.yml +26 -0
  1350. data/spec/spec_tests/data/server_selection/ReplicaSetNoPrimary/read/Nearest_non_matching.yml +20 -0
  1351. data/spec/spec_tests/data/server_selection/ReplicaSetNoPrimary/read/PossiblePrimary.yml +15 -0
  1352. data/spec/spec_tests/data/server_selection/ReplicaSetNoPrimary/read/PossiblePrimaryNearest.yml +15 -0
  1353. data/spec/spec_tests/data/server_selection/ReplicaSetNoPrimary/read/Primary.yml +18 -0
  1354. data/spec/spec_tests/data/server_selection/ReplicaSetNoPrimary/read/PrimaryPreferred.yml +25 -0
  1355. data/spec/spec_tests/data/server_selection/ReplicaSetNoPrimary/read/PrimaryPreferred_non_matching.yml +20 -0
  1356. data/spec/spec_tests/data/server_selection/ReplicaSetNoPrimary/read/Secondary.yml +25 -0
  1357. data/spec/spec_tests/data/server_selection/ReplicaSetNoPrimary/read/SecondaryPreferred.yml +25 -0
  1358. data/spec/spec_tests/data/server_selection/ReplicaSetNoPrimary/read/SecondaryPreferred_non_matching.yml +20 -0
  1359. data/spec/spec_tests/data/server_selection/ReplicaSetNoPrimary/read/Secondary_multi_tags.yml +31 -0
  1360. data/spec/spec_tests/data/server_selection/ReplicaSetNoPrimary/read/Secondary_multi_tags2.yml +31 -0
  1361. data/spec/spec_tests/data/server_selection/ReplicaSetNoPrimary/read/Secondary_non_matching.yml +20 -0
  1362. data/spec/spec_tests/data/server_selection/ReplicaSetWithPrimary/read/Nearest.yml +32 -0
  1363. data/spec/spec_tests/data/server_selection/ReplicaSetWithPrimary/read/Nearest_multiple.yml +33 -0
  1364. data/spec/spec_tests/data/server_selection/ReplicaSetWithPrimary/read/Nearest_non_matching.yml +25 -0
  1365. data/spec/spec_tests/data/server_selection/ReplicaSetWithPrimary/read/Primary.yml +26 -0
  1366. data/spec/spec_tests/data/server_selection/ReplicaSetWithPrimary/read/PrimaryPreferred.yml +28 -0
  1367. data/spec/spec_tests/data/server_selection/ReplicaSetWithPrimary/read/PrimaryPreferred_non_matching.yml +28 -0
  1368. data/spec/spec_tests/data/server_selection/ReplicaSetWithPrimary/read/Secondary.yml +30 -0
  1369. data/spec/spec_tests/data/server_selection/ReplicaSetWithPrimary/read/SecondaryPreferred.yml +30 -0
  1370. data/spec/spec_tests/data/server_selection/ReplicaSetWithPrimary/read/SecondaryPreferred_non_matching.yml +28 -0
  1371. data/spec/spec_tests/data/server_selection/ReplicaSetWithPrimary/read/SecondaryPreferred_tags.yml +28 -0
  1372. data/spec/spec_tests/data/server_selection/ReplicaSetWithPrimary/read/Secondary_non_matching.yml +25 -0
  1373. data/spec/spec_tests/data/server_selection/Sharded/read/Nearest.yml +21 -0
  1374. data/spec/spec_tests/data/server_selection/Sharded/read/Primary.yml +19 -0
  1375. data/spec/spec_tests/data/server_selection/Sharded/read/PrimaryPreferred.yml +21 -0
  1376. data/spec/spec_tests/data/server_selection/Sharded/read/Secondary.yml +21 -0
  1377. data/spec/spec_tests/data/server_selection/Sharded/read/SecondaryPreferred.yml +21 -0
  1378. data/spec/spec_tests/data/server_selection/Single/read/SecondaryPreferred.yml +18 -0
  1379. data/spec/spec_tests/data/server_selection/Unknown/read/SecondaryPreferred.yml +10 -0
  1380. data/spec/spec_tests/data/server_selection_rtt/first_value.yml +4 -0
  1381. data/spec/spec_tests/data/server_selection_rtt/first_value_zero.yml +4 -0
  1382. data/spec/spec_tests/data/server_selection_rtt/value_test_1.yml +4 -0
  1383. data/spec/spec_tests/data/server_selection_rtt/value_test_2.yml +4 -0
  1384. data/spec/spec_tests/data/server_selection_rtt/value_test_3.yml +4 -0
  1385. data/spec/spec_tests/data/server_selection_rtt/value_test_4.yml +4 -0
  1386. data/spec/spec_tests/data/server_selection_rtt/value_test_5.yml +4 -0
  1387. data/spec/spec_tests/data/transactions/abort.yml +413 -0
  1388. data/spec/spec_tests/data/transactions/bulk.yml +267 -0
  1389. data/spec/spec_tests/data/transactions/causal-consistency.yml +175 -0
  1390. data/spec/spec_tests/data/transactions/commit.yml +603 -0
  1391. data/spec/spec_tests/data/transactions/count.yml +67 -0
  1392. data/spec/spec_tests/data/transactions/create-collection.yml +131 -0
  1393. data/spec/spec_tests/data/transactions/create-index.yml +152 -0
  1394. data/spec/spec_tests/data/transactions/delete.yml +192 -0
  1395. data/spec/spec_tests/data/transactions/error-labels.yml +1030 -0
  1396. data/spec/spec_tests/data/transactions/errors-client.yml +56 -0
  1397. data/spec/spec_tests/data/transactions/errors.yml +133 -0
  1398. data/spec/spec_tests/data/transactions/findOneAndDelete.yml +134 -0
  1399. data/spec/spec_tests/data/transactions/findOneAndReplace.yml +148 -0
  1400. data/spec/spec_tests/data/transactions/findOneAndUpdate.yml +236 -0
  1401. data/spec/spec_tests/data/transactions/insert.yml +390 -0
  1402. data/spec/spec_tests/data/transactions/isolation.yml +133 -0
  1403. data/spec/spec_tests/data/transactions/mongos-pin-auto.yml +1674 -0
  1404. data/spec/spec_tests/data/transactions/mongos-recovery-token.yml +350 -0
  1405. data/spec/spec_tests/data/transactions/pin-mongos.yml +559 -0
  1406. data/spec/spec_tests/data/transactions/read-concern.yml +623 -0
  1407. data/spec/spec_tests/data/transactions/read-pref.yml +348 -0
  1408. data/spec/spec_tests/data/transactions/reads.yml +261 -0
  1409. data/spec/spec_tests/data/transactions/retryable-abort-errorLabels.yml +124 -0
  1410. data/spec/spec_tests/data/transactions/retryable-abort.yml +1315 -0
  1411. data/spec/spec_tests/data/transactions/retryable-commit-errorLabels.yml +132 -0
  1412. data/spec/spec_tests/data/transactions/retryable-commit.yml +1460 -0
  1413. data/spec/spec_tests/data/transactions/retryable-writes.yml +216 -0
  1414. data/spec/spec_tests/data/transactions/run-command.yml +197 -0
  1415. data/spec/spec_tests/data/transactions/transaction-options-repl.yml +117 -0
  1416. data/spec/spec_tests/data/transactions/transaction-options.yml +781 -0
  1417. data/spec/spec_tests/data/transactions/update.yml +246 -0
  1418. data/spec/spec_tests/data/transactions/write-concern.yml +554 -0
  1419. data/spec/spec_tests/data/transactions_api/callback-aborts.yml +170 -0
  1420. data/spec/spec_tests/data/transactions_api/callback-commits.yml +204 -0
  1421. data/spec/spec_tests/data/transactions_api/callback-retry.yml +215 -0
  1422. data/spec/spec_tests/data/transactions_api/commit-retry.yml +324 -0
  1423. data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror-4.2.yml +139 -0
  1424. data/spec/spec_tests/data/transactions_api/commit-transienttransactionerror.yml +175 -0
  1425. data/spec/spec_tests/data/transactions_api/commit-writeconcernerror.yml +216 -0
  1426. data/spec/spec_tests/data/transactions_api/commit.yml +193 -0
  1427. data/spec/spec_tests/data/transactions_api/transaction-options.yml +274 -0
  1428. data/spec/spec_tests/data/transactions_unified/mongos-unpin.yml +172 -0
  1429. data/spec/spec_tests/data/unified/valid-fail/operation-failure.yml +31 -0
  1430. data/spec/spec_tests/data/unified/valid-pass/poc-change-streams.yml +220 -0
  1431. data/spec/spec_tests/data/unified/valid-pass/poc-command-monitoring.yml +102 -0
  1432. data/spec/spec_tests/data/unified/valid-pass/poc-crud.yml +184 -0
  1433. data/spec/spec_tests/data/unified/valid-pass/poc-gridfs.yml +155 -0
  1434. data/spec/spec_tests/data/unified/valid-pass/poc-retryable-reads.yml +193 -0
  1435. data/spec/spec_tests/data/unified/valid-pass/poc-retryable-writes.yml +210 -0
  1436. data/spec/spec_tests/data/unified/valid-pass/poc-sessions.yml +215 -0
  1437. data/spec/spec_tests/data/unified/valid-pass/poc-transactions-convenient-api.yml +235 -0
  1438. data/spec/spec_tests/data/unified/valid-pass/poc-transactions-mongos-pin-auto.yml +169 -0
  1439. data/spec/spec_tests/data/unified/valid-pass/poc-transactions.yml +170 -0
  1440. data/spec/spec_tests/data/uri_options/auth-options.yml +49 -0
  1441. data/spec/spec_tests/data/uri_options/compression-options.yml +51 -0
  1442. data/spec/spec_tests/data/uri_options/concern-options.yml +55 -0
  1443. data/spec/spec_tests/data/uri_options/connection-options.yml +149 -0
  1444. data/spec/spec_tests/data/uri_options/connection-pool-options.yml +26 -0
  1445. data/spec/spec_tests/data/uri_options/read-preference-options.yml +66 -0
  1446. data/spec/spec_tests/data/uri_options/ruby-auth-options.yml +12 -0
  1447. data/spec/spec_tests/data/uri_options/ruby-connection-options.yml +58 -0
  1448. data/spec/spec_tests/data/uri_options/tls-options.yml +364 -0
  1449. data/spec/spec_tests/data/versioned_api/crud-api-version-1-strict.yml +417 -0
  1450. data/spec/spec_tests/data/versioned_api/crud-api-version-1.yml +411 -0
  1451. data/spec/spec_tests/data/versioned_api/runcommand-helper-no-api-version-declared.yml +75 -0
  1452. data/spec/spec_tests/data/versioned_api/test-commands-deprecation-errors.yml +47 -0
  1453. data/spec/spec_tests/data/versioned_api/test-commands-strict-mode.yml +46 -0
  1454. data/spec/spec_tests/data/versioned_api/transaction-handling.yml +128 -0
  1455. data/spec/spec_tests/dns_seedlist_discovery_spec.rb +79 -0
  1456. data/spec/spec_tests/gridfs_spec.rb +55 -0
  1457. data/spec/spec_tests/max_staleness_spec.rb +12 -0
  1458. data/spec/spec_tests/read_write_concern_connection_string_spec.rb +13 -0
  1459. data/spec/spec_tests/read_write_concern_document_spec.rb +77 -0
  1460. data/spec/spec_tests/read_write_concern_operaton_spec.rb +13 -0
  1461. data/spec/spec_tests/retryable_reads_spec.rb +50 -0
  1462. data/spec/spec_tests/retryable_writes_spec.rb +22 -0
  1463. data/spec/spec_tests/sdam_integration_spec.rb +16 -0
  1464. data/spec/spec_tests/sdam_monitoring_spec.rb +96 -0
  1465. data/spec/spec_tests/sdam_spec.rb +242 -0
  1466. data/spec/spec_tests/server_selection_rtt_spec.rb +33 -0
  1467. data/spec/spec_tests/server_selection_spec.rb +12 -0
  1468. data/spec/spec_tests/transactions_api_spec.rb +13 -0
  1469. data/spec/spec_tests/transactions_spec.rb +13 -0
  1470. data/spec/spec_tests/transactions_unified_spec.rb +13 -0
  1471. data/spec/spec_tests/unified_spec.rb +18 -0
  1472. data/spec/spec_tests/uri_options_spec.rb +93 -0
  1473. data/spec/spec_tests/versioned_api_spec.rb +13 -0
  1474. data/spec/stress/cleanup_spec.rb +61 -0
  1475. data/spec/stress/connection_pool_stress_spec.rb +204 -0
  1476. data/spec/stress/connection_pool_timing_spec.rb +184 -0
  1477. data/spec/stress/fork_reconnect_stress_spec.rb +112 -0
  1478. data/spec/stress/push_monitor_close_spec.rb +44 -0
  1479. data/spec/support/authorization.rb +161 -0
  1480. data/spec/support/aws_utils/base.rb +137 -0
  1481. data/spec/support/aws_utils/inspector.rb +227 -0
  1482. data/spec/support/aws_utils/orchestrator.rb +373 -0
  1483. data/spec/support/aws_utils/provisioner.rb +363 -0
  1484. data/spec/support/aws_utils.rb +65 -0
  1485. data/spec/support/background_thread_registry.rb +70 -0
  1486. data/spec/support/certificates/README.md +106 -0
  1487. data/spec/support/certificates/atlas-ocsp-ca.crt +118 -0
  1488. data/spec/support/certificates/atlas-ocsp.crt +152 -0
  1489. data/spec/support/certificates/ca.crt +76 -0
  1490. data/spec/support/certificates/client-encrypted.key +30 -0
  1491. data/spec/support/certificates/client-int.crt +78 -0
  1492. data/spec/support/certificates/client-second-level-bundle.pem +179 -0
  1493. data/spec/support/certificates/client-second-level.crt +74 -0
  1494. data/spec/support/certificates/client-second-level.key +27 -0
  1495. data/spec/support/certificates/client-second-level.pem +101 -0
  1496. data/spec/support/certificates/client-x509.crt +78 -0
  1497. data/spec/support/certificates/client-x509.key +27 -0
  1498. data/spec/support/certificates/client-x509.pem +105 -0
  1499. data/spec/support/certificates/client.crt +74 -0
  1500. data/spec/support/certificates/client.key +27 -0
  1501. data/spec/support/certificates/client.pem +101 -0
  1502. data/spec/support/certificates/crl.pem +12 -0
  1503. data/spec/support/certificates/crl_client_revoked.pem +13 -0
  1504. data/spec/support/certificates/multi-ca.crt +152 -0
  1505. data/spec/support/certificates/python-ca.crt +76 -0
  1506. data/spec/support/certificates/server-int.crt +78 -0
  1507. data/spec/support/certificates/server-second-level-bundle.pem +179 -0
  1508. data/spec/support/certificates/server-second-level.crt +74 -0
  1509. data/spec/support/certificates/server-second-level.key +27 -0
  1510. data/spec/support/certificates/server-second-level.pem +101 -0
  1511. data/spec/support/certificates/server.pem +101 -0
  1512. data/spec/support/client_registry.rb +254 -0
  1513. data/spec/support/client_registry_macros.rb +26 -0
  1514. data/spec/support/cluster_tools.rb +379 -0
  1515. data/spec/support/common_shortcuts.rb +375 -0
  1516. data/spec/support/constraints.rb +19 -0
  1517. data/spec/support/crypt/corpus/corpus-key-aws.json +33 -0
  1518. data/spec/support/crypt/corpus/corpus-key-local.json +31 -0
  1519. data/spec/support/crypt/corpus/corpus-schema.json +2057 -0
  1520. data/spec/support/crypt/corpus/corpus.json +3657 -0
  1521. data/spec/support/crypt/corpus/corpus_encrypted.json +4152 -0
  1522. data/spec/support/crypt/data_keys/key_document_aws.json +34 -0
  1523. data/spec/support/crypt/data_keys/key_document_local.json +31 -0
  1524. data/spec/support/crypt/external/external-key.json +31 -0
  1525. data/spec/support/crypt/external/external-schema.json +19 -0
  1526. data/spec/support/crypt/limits/limits-doc.json +102 -0
  1527. data/spec/support/crypt/limits/limits-key.json +31 -0
  1528. data/spec/support/crypt/limits/limits-schema.json +1405 -0
  1529. data/spec/support/crypt/schema_maps/schema_map_aws.json +17 -0
  1530. data/spec/support/crypt/schema_maps/schema_map_aws_key_alt_names.json +12 -0
  1531. data/spec/support/crypt/schema_maps/schema_map_local.json +18 -0
  1532. data/spec/support/crypt/schema_maps/schema_map_local_key_alt_names.json +12 -0
  1533. data/spec/support/crypt.rb +157 -0
  1534. data/spec/support/dns.rb +16 -0
  1535. data/spec/support/event_subscriber.rb +221 -0
  1536. data/spec/support/json_ext_formatter.rb +16 -0
  1537. data/spec/support/keyword_struct.rb +29 -0
  1538. data/spec/support/local_resource_registry.rb +37 -0
  1539. data/spec/support/matchers.rb +75 -0
  1540. data/spec/support/monitoring_ext.rb +19 -0
  1541. data/spec/support/ocsp +1 -0
  1542. data/spec/support/primary_socket.rb +24 -0
  1543. data/spec/support/sdam_formatter_integration.rb +119 -0
  1544. data/spec/support/session_registry.rb +55 -0
  1545. data/spec/support/shared/app_metadata.rb +167 -0
  1546. data/spec/support/shared/protocol.rb +36 -0
  1547. data/spec/support/shared/scram_conversation.rb +103 -0
  1548. data/spec/support/shared/server_selector.rb +233 -0
  1549. data/spec/support/shared/session.rb +910 -0
  1550. data/spec/support/spec_config.rb +637 -0
  1551. data/spec/support/spec_setup.rb +83 -0
  1552. data/spec/support/utils.rb +598 -0
  1553. data.tar.gz.sig +0 -0
  1554. metadata +2696 -179
  1555. metadata.gz.sig +0 -0
  1556. data/VERSION +0 -1
  1557. data/lib/mongo/db.rb +0 -644
  1558. data/lib/mongo/exceptions.rb +0 -65
  1559. data/lib/mongo/gridfs/grid.rb +0 -101
  1560. data/lib/mongo/gridfs/grid_ext.rb +0 -39
  1561. data/lib/mongo/gridfs/grid_file_system.rb +0 -150
  1562. data/lib/mongo/gridfs/grid_io.rb +0 -472
  1563. data/lib/mongo/legacy.rb +0 -71
  1564. data/lib/mongo/mongo_client.rb +0 -657
  1565. data/lib/mongo/mongo_replica_set_client.rb +0 -485
  1566. data/lib/mongo/mongo_sharded_client.rb +0 -144
  1567. data/lib/mongo/networking.rb +0 -343
  1568. data/lib/mongo/util/conversions.rb +0 -95
  1569. data/lib/mongo/util/core_ext.rb +0 -87
  1570. data/lib/mongo/util/logging.rb +0 -69
  1571. data/lib/mongo/util/node.rb +0 -197
  1572. data/lib/mongo/util/pool.rb +0 -316
  1573. data/lib/mongo/util/pool_manager.rb +0 -270
  1574. data/lib/mongo/util/read_preference.rb +0 -112
  1575. data/lib/mongo/util/server_version.rb +0 -54
  1576. data/lib/mongo/util/sharding_pool_manager.rb +0 -54
  1577. data/lib/mongo/util/socket_util.rb +0 -20
  1578. data/lib/mongo/util/ssl_socket.rb +0 -51
  1579. data/lib/mongo/util/support.rb +0 -113
  1580. data/lib/mongo/util/tcp_socket.rb +0 -62
  1581. data/lib/mongo/util/thread_local_variable_manager.rb +0 -11
  1582. data/lib/mongo/util/unix_socket.rb +0 -23
  1583. data/lib/mongo/util/uri_parser.rb +0 -337
  1584. data/lib/mongo/util/write_concern.rb +0 -54
  1585. data/test/functional/authentication_test.rb +0 -18
  1586. data/test/functional/collection_test.rb +0 -1410
  1587. data/test/functional/connection_test.rb +0 -449
  1588. data/test/functional/conversions_test.rb +0 -119
  1589. data/test/functional/cursor_fail_test.rb +0 -49
  1590. data/test/functional/cursor_message_test.rb +0 -43
  1591. data/test/functional/cursor_test.rb +0 -548
  1592. data/test/functional/db_api_test.rb +0 -805
  1593. data/test/functional/db_connection_test.rb +0 -13
  1594. data/test/functional/db_test.rb +0 -282
  1595. data/test/functional/grid_file_system_test.rb +0 -273
  1596. data/test/functional/grid_io_test.rb +0 -238
  1597. data/test/functional/grid_test.rb +0 -259
  1598. data/test/functional/pool_test.rb +0 -47
  1599. data/test/functional/safe_test.rb +0 -84
  1600. data/test/functional/support_test.rb +0 -48
  1601. data/test/functional/threading_test.rb +0 -95
  1602. data/test/functional/timeout_test.rb +0 -60
  1603. data/test/functional/uri_test.rb +0 -200
  1604. data/test/functional/write_concern_test.rb +0 -104
  1605. data/test/replica_set/authentication_test.rb +0 -20
  1606. data/test/replica_set/basic_test.rb +0 -133
  1607. data/test/replica_set/client_test.rb +0 -264
  1608. data/test/replica_set/complex_connect_test.rb +0 -64
  1609. data/test/replica_set/connection_test.rb +0 -116
  1610. data/test/replica_set/count_test.rb +0 -50
  1611. data/test/replica_set/cursor_test.rb +0 -198
  1612. data/test/replica_set/insert_test.rb +0 -50
  1613. data/test/replica_set/max_values_test.rb +0 -76
  1614. data/test/replica_set/pinning_test.rb +0 -41
  1615. data/test/replica_set/query_test.rb +0 -59
  1616. data/test/replica_set/read_preference_test.rb +0 -200
  1617. data/test/replica_set/refresh_test.rb +0 -161
  1618. data/test/replica_set/replication_ack_test.rb +0 -74
  1619. data/test/sharded_cluster/basic_test.rb +0 -155
  1620. data/test/shared/authentication.rb +0 -66
  1621. data/test/test_helper.rb +0 -210
  1622. data/test/threading/basic_test.rb +0 -80
  1623. data/test/tools/mongo_config.rb +0 -568
  1624. data/test/tools/mongo_config_test.rb +0 -146
  1625. data/test/unit/client_test.rb +0 -252
  1626. data/test/unit/collection_test.rb +0 -176
  1627. data/test/unit/connection_test.rb +0 -246
  1628. data/test/unit/cursor_test.rb +0 -273
  1629. data/test/unit/db_test.rb +0 -112
  1630. data/test/unit/grid_test.rb +0 -62
  1631. data/test/unit/mongo_sharded_client_test.rb +0 -32
  1632. data/test/unit/node_test.rb +0 -78
  1633. data/test/unit/pool_manager_test.rb +0 -94
  1634. data/test/unit/pool_test.rb +0 -9
  1635. data/test/unit/read_pref_test.rb +0 -21
  1636. data/test/unit/read_test.rb +0 -145
  1637. data/test/unit/safe_test.rb +0 -144
  1638. data/test/unit/sharding_pool_manager_test.rb +0 -63
  1639. data/test/unit/util_test.rb +0 -55
  1640. data/test/unit/write_concern_test.rb +0 -161
@@ -1,1131 +1,922 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ # Copyright (C) 2014-2020 MongoDB Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'mongo/bulk_write'
19
+ require 'mongo/collection/view'
20
+
1
21
  module Mongo
2
22
 
3
- # A named collection of documents in a database.
23
+ # Represents a collection in the database and operations that can directly be
24
+ # applied to one.
25
+ #
26
+ # @since 2.0.0
4
27
  class Collection
5
- include Mongo::Logging
6
- include Mongo::WriteConcern
28
+ extend Forwardable
29
+ include Retryable
7
30
 
8
- attr_reader :db,
9
- :name,
10
- :pk_factory,
11
- :hint,
12
- :write_concern,
13
- :capped
31
+ # The capped option.
32
+ #
33
+ # @since 2.1.0
34
+ CAPPED = 'capped'.freeze
14
35
 
15
- # Read Preference
16
- attr_accessor :read,
17
- :tag_sets,
18
- :acceptable_latency
36
+ # The ns field constant.
37
+ #
38
+ # @since 2.1.0
39
+ NS = 'ns'.freeze
19
40
 
20
- # Initialize a collection object.
21
- #
22
- # @param [String, Symbol] name the name of the collection.
23
- # @param [DB] db a MongoDB database instance.
24
- #
25
- # @option opts [String, Integer, Symbol] :w (1) Set default number of nodes to which a write
26
- # should be acknowledged
27
- # @option opts [Boolean] :j (false) Set journal acknowledgement
28
- # @option opts [Integer] :wtimeout (nil) Set replica set acknowledgement timeout
29
- # @option opts [Boolean] :fsync (false) Set fsync acknowledgement.
30
- #
31
- # Notes about write concern:
32
- # These write concern options will be used for insert, update, and remove methods called on this
33
- # Collection instance. If no value is provided, the default values set on this instance's DB will be used.
34
- # These option values can be overridden for any invocation of insert, update, or remove.
35
- #
36
- # @option opts [:create_pk] :pk (BSON::ObjectId) A primary key factory to use
37
- # other than the default BSON::ObjectId.
38
- # @option opts [:primary, :secondary] :read The default read preference for queries
39
- # initiates from this connection object. If +:secondary+ is chosen, reads will be sent
40
- # to one of the closest available secondary nodes. If a secondary node cannot be located, the
41
- # read will be sent to the primary. If this option is left unspecified, the value of the read
42
- # preference for this collection's associated Mongo::DB object will be used.
43
- #
44
- # @raise [InvalidNSName]
45
- # if collection name is empty, contains '$', or starts or ends with '.'
46
- #
47
- # @raise [TypeError]
48
- # if collection name is not a string or symbol
49
- #
50
- # @return [Collection]
51
- #
52
- # @core collections constructor_details
53
- def initialize(name, db, opts={})
54
- if db.is_a?(String) && name.is_a?(Mongo::DB)
55
- warn "Warning: the order of parameters to initialize a collection have changed. " +
56
- "Please specify the collection name first, followed by the db. This will be made permanent" +
57
- "in v2.0."
58
- db, name = name, db
59
- end
41
+ # @return [ Mongo::Database ] The database the collection resides in.
42
+ attr_reader :database
60
43
 
61
- raise TypeError,
62
- "Collection name must be a String or Symbol." unless [String, Symbol].include?(name.class)
63
- name = name.to_s
44
+ # @return [ String ] The name of the collection.
45
+ attr_reader :name
64
46
 
65
- raise Mongo::InvalidNSName,
66
- "Collection names cannot be empty." if name.empty? || name.include?("..")
47
+ # @return [ Hash ] The collection options.
48
+ attr_reader :options
67
49
 
68
- if name.include?("$")
69
- raise Mongo::InvalidNSName,
70
- "Collection names must not contain '$'" unless name =~ /((^\$cmd)|(oplog\.\$main))/
71
- end
50
+ # Get client, cluster, read preference, and write concern from client.
51
+ def_delegators :database, :client, :cluster
72
52
 
73
- raise Mongo::InvalidNSName,
74
- "Collection names must not start or end with '.'" if name.match(/^\./) || name.match(/\.$/)
53
+ # Delegate to the cluster for the next primary.
54
+ def_delegators :cluster, :next_primary
75
55
 
76
- pk_factory = nil
77
- if opts.respond_to?(:create_pk) || !opts.is_a?(Hash)
78
- warn "The method for specifying a primary key factory on a Collection has changed.\n" +
79
- "Please specify it as an option (e.g., :pk => PkFactory)."
80
- pk_factory = opts
81
- end
56
+ # Options that can be updated on a new Collection instance via the #with method.
57
+ #
58
+ # @since 2.1.0
59
+ CHANGEABLE_OPTIONS = [ :read, :read_concern, :write, :write_concern ].freeze
82
60
 
83
- @db, @name = db, name
84
- @connection = @db.connection
85
- @logger = @connection.logger
86
- @cache_time = @db.cache_time
87
- @cache = Hash.new(0)
88
- unless pk_factory
89
- @write_concern = get_write_concern(opts, db)
90
- @read = opts[:read] || @db.read
91
- Mongo::ReadPreference::validate(@read)
92
- @capped = opts[:capped]
93
- @tag_sets = opts.fetch(:tag_sets, @db.tag_sets)
94
- @acceptable_latency = opts.fetch(:acceptable_latency, @db.acceptable_latency)
95
- end
96
- @pk_factory = pk_factory || opts[:pk] || BSON::ObjectId
97
- @hint = nil
98
- end
61
+ # Options that can be used for creating a time-series collection.
62
+ TIME_SERIES_OPTIONS = {
63
+ :time_series => :timeseries,
64
+ :expire_after => :expireAfterSeconds
65
+ }
99
66
 
100
- # Indicate whether this is a capped collection.
67
+ # Check if a collection is equal to another object. Will check the name and
68
+ # the database for equality.
101
69
  #
102
- # @raise [Mongo::OperationFailure]
103
- # if the collection doesn't exist.
70
+ # @example Check collection equality.
71
+ # collection == other
104
72
  #
105
- # @return [Boolean]
106
- def capped?
107
- @capped ||= [1, true].include?(@db.command({:collstats => @name})['capped'])
108
- end
109
-
110
- # Return a sub-collection of this collection by name. If 'users' is a collection, then
111
- # 'users.comments' is a sub-collection of users.
112
- #
113
- # @param [String, Symbol] name
114
- # the collection to return
115
- #
116
- # @raise [Mongo::InvalidNSName]
117
- # if passed an invalid collection name
118
- #
119
- # @return [Collection]
120
- # the specified sub-collection
121
- def [](name)
122
- name = "#{self.name}.#{name}"
123
- return Collection.new(name, db) if !db.strict? ||
124
- db.collection_names.include?(name.to_s)
125
- raise "Collection #{name} doesn't exist. Currently in strict mode."
126
- end
127
-
128
- # Set a hint field for query optimizer. Hint may be a single field
129
- # name, array of field names, or a hash (preferably an [OrderedHash]).
130
- # If using MongoDB > 1.1, you probably don't ever need to set a hint.
131
- #
132
- # @param [String, Array, OrderedHash] hint a single field, an array of
133
- # fields, or a hash specifying fields
134
- def hint=(hint=nil)
135
- @hint = normalize_hint_fields(hint)
136
- self
137
- end
138
-
139
- # Set a hint field using a named index.
140
- # @param [String] hinted index name
141
- def named_hint=(hint=nil)
142
- @hint = hint
143
- self
73
+ # @param [ Object ] other The object to check.
74
+ #
75
+ # @return [ true, false ] If the objects are equal.
76
+ #
77
+ # @since 2.0.0
78
+ def ==(other)
79
+ return false unless other.is_a?(Collection)
80
+ name == other.name && database == other.database && options == other.options
144
81
  end
145
82
 
146
- # Query the database.
147
- #
148
- # The +selector+ argument is a prototype document that all results must
149
- # match. For example:
150
- #
151
- # collection.find({"hello" => "world"})
152
- #
153
- # only matches documents that have a key "hello" with value "world".
154
- # Matches can have other keys *in addition* to "hello".
155
- #
156
- # If given an optional block +find+ will yield a Cursor to that block,
157
- # close the cursor, and then return nil. This guarantees that partially
158
- # evaluated cursors will be closed. If given no block +find+ returns a
159
- # cursor.
160
- #
161
- # @param [Hash] selector
162
- # a document specifying elements which must be present for a
163
- # document to be included in the result set. Note that in rare cases,
164
- # (e.g., with $near queries), the order of keys will matter. To preserve
165
- # key order on a selector, use an instance of BSON::OrderedHash (only applies
166
- # to Ruby 1.8).
167
- #
168
- # @option opts [Array, Hash] :fields field names that should be returned in the result
169
- # set ("_id" will be included unless explicitly excluded). By limiting results to a certain subset of fields,
170
- # you can cut down on network traffic and decoding time. If using a Hash, keys should be field
171
- # names and values should be either 1 or 0, depending on whether you want to include or exclude
172
- # the given field.
173
- # @option opts [:primary, :secondary] :read The default read preference for queries
174
- # initiates from this connection object. If +:secondary+ is chosen, reads will be sent
175
- # to one of the closest available secondary nodes. If a secondary node cannot be located, the
176
- # read will be sent to the primary. If this option is left unspecified, the value of the read
177
- # preference for this Collection object will be used.
178
- # @option opts [Integer] :skip number of documents to skip from the beginning of the result set
179
- # @option opts [Integer] :limit maximum number of documents to return
180
- # @option opts [Array] :sort an array of [key, direction] pairs to sort by. Direction should
181
- # be specified as Mongo::ASCENDING (or :ascending / :asc) or Mongo::DESCENDING (or :descending / :desc)
182
- # @option opts [String, Array, OrderedHash] :hint hint for query optimizer, usually not necessary if
183
- # using MongoDB > 1.1
184
- # @option opts [String] :named_hint for specifying a named index as a hint, will be overriden by :hint
185
- # if :hint is also provided.
186
- # @option opts [Boolean] :snapshot (false) if true, snapshot mode will be used for this query.
187
- # Snapshot mode assures no duplicates are returned, or objects missed, which were preset at both the start and
188
- # end of the query's execution.
189
- # For details see http://www.mongodb.org/display/DOCS/How+to+do+Snapshotting+in+the+Mongo+Database
190
- # @option opts [Boolean] :batch_size (100) the number of documents to returned by the database per
191
- # GETMORE operation. A value of 0 will let the database server decide how many results to return.
192
- # This option can be ignored for most use cases.
193
- # @option opts [Boolean] :timeout (true) when +true+, the returned cursor will be subject to
194
- # the normal cursor timeout behavior of the mongod process. When +false+, the returned cursor will
195
- # never timeout. Note that disabling timeout will only work when #find is invoked with a block.
196
- # This is to prevent any inadvertent failure to close the cursor, as the cursor is explicitly
197
- # closed when block code finishes.
198
- # @option opts [Integer] :max_scan (nil) Limit the number of items to scan on both collection scans and indexed queries..
199
- # @option opts [Boolean] :show_disk_loc (false) Return the disk location of each query result (for debugging).
200
- # @option opts [Boolean] :return_key (false) Return the index key used to obtain the result (for debugging).
201
- # @option opts [Block] :transformer (nil) a block for transforming returned documents.
202
- # This is normally used by object mappers to convert each returned document to an instance of a class.
203
- # @option opts [String] :comment (nil) a comment to include in profiling logs
204
- #
205
- # @raise [ArgumentError]
206
- # if timeout is set to false and find is not invoked in a block
207
- #
208
- # @raise [RuntimeError]
209
- # if given unknown options
210
- #
211
- # @core find find-instance_method
212
- def find(selector={}, opts={})
213
- opts = opts.dup
214
- fields = opts.delete(:fields)
215
- fields = ["_id"] if fields && fields.empty?
216
- skip = opts.delete(:skip) || skip || 0
217
- limit = opts.delete(:limit) || 0
218
- sort = opts.delete(:sort)
219
- hint = opts.delete(:hint)
220
- named_hint = opts.delete(:named_hint)
221
- snapshot = opts.delete(:snapshot)
222
- batch_size = opts.delete(:batch_size)
223
- timeout = (opts.delete(:timeout) == false) ? false : true
224
- max_scan = opts.delete(:max_scan)
225
- return_key = opts.delete(:return_key)
226
- transformer = opts.delete(:transformer)
227
- show_disk_loc = opts.delete(:show_disk_loc)
228
- comment = opts.delete(:comment)
229
- read = opts.delete(:read) || @read
230
- tag_sets = opts.delete(:tag_sets) || @tag_sets
231
- acceptable_latency = opts.delete(:acceptable_latency) || @acceptable_latency
232
-
233
- if timeout == false && !block_given?
234
- raise ArgumentError, "Collection#find must be invoked with a block when timeout is disabled."
235
- end
236
-
237
- if hint
238
- hint = normalize_hint_fields(hint)
239
- else
240
- hint = @hint # assumed to be normalized already
83
+ # Instantiate a new collection.
84
+ #
85
+ # @example Instantiate a new collection.
86
+ # Mongo::Collection.new(database, 'test')
87
+ #
88
+ # @param [ Mongo::Database ] database The collection's database.
89
+ # @param [ String, Symbol ] name The collection name.
90
+ # @param [ Hash ] options The collection options.
91
+ #
92
+ # @option options [ Hash ] :write Deprecated. Equivalent to :write_concern
93
+ # option.
94
+ # @option options [ Hash ] :write_concern The write concern options.
95
+ # Can be :w => Integer|String, :fsync => Boolean, :j => Boolean.
96
+ # @option options [ Hash ] :time_series Create a time-series collection.
97
+ # See https://docs.mongodb.com/manual/core/timeseries-collections/ for more
98
+ # information about time-series collection.
99
+ # @option options [ Integer ] :expire_after Number indicating
100
+ # after how many seconds old time-series data should be deleted.
101
+ #
102
+ # @since 2.0.0
103
+ def initialize(database, name, options = {})
104
+ raise Error::InvalidCollectionName.new unless name
105
+ if options[:write] && options[:write_concern] && options[:write] != options[:write_concern]
106
+ raise ArgumentError, "If :write and :write_concern are both given, they must be identical: #{options.inspect}"
241
107
  end
242
-
243
- raise RuntimeError, "Unknown options [#{opts.inspect}]" unless opts.empty?
244
-
245
- cursor = Cursor.new(self, {
246
- :selector => selector,
247
- :fields => fields,
248
- :skip => skip,
249
- :limit => limit,
250
- :order => sort,
251
- :hint => hint || named_hint,
252
- :snapshot => snapshot,
253
- :timeout => timeout,
254
- :batch_size => batch_size,
255
- :transformer => transformer,
256
- :max_scan => max_scan,
257
- :show_disk_loc => show_disk_loc,
258
- :return_key => return_key,
259
- :read => read,
260
- :tag_sets => tag_sets,
261
- :comment => comment,
262
- :acceptable_latency => acceptable_latency
263
- })
264
-
265
- if block_given?
266
- begin
267
- yield cursor
268
- ensure
269
- cursor.close
270
- end
271
- nil
272
- else
273
- cursor
108
+ @database = database
109
+ @name = name.to_s.freeze
110
+ @options = options.dup
111
+ =begin WriteConcern object support
112
+ if @options[:write_concern].is_a?(WriteConcern::Base)
113
+ # Cache the instance so that we do not needlessly reconstruct it.
114
+ @write_concern = @options[:write_concern]
115
+ @options[:write_concern] = @write_concern.options
274
116
  end
117
+ =end
118
+ @options.freeze
275
119
  end
276
120
 
277
- # Return a single object from the database.
278
- #
279
- # @return [OrderedHash, Nil]
280
- # a single document or nil if no result is found.
281
- #
282
- # @param [Hash, ObjectId, Nil] spec_or_object_id a hash specifying elements
283
- # which must be present for a document to be included in the result set or an
284
- # instance of ObjectId to be used as the value for an _id query.
285
- # If nil, an empty selector, {}, will be used.
286
- #
287
- # @option opts [Hash]
288
- # any valid options that can be send to Collection#find
289
- #
290
- # @raise [TypeError]
291
- # if the argument is of an improper type.
292
- def find_one(spec_or_object_id=nil, opts={})
293
- spec = case spec_or_object_id
294
- when nil
295
- {}
296
- when BSON::ObjectId
297
- {:_id => spec_or_object_id}
298
- when Hash
299
- spec_or_object_id
300
- else
301
- raise TypeError, "spec_or_object_id must be an instance of ObjectId or Hash, or nil"
302
- end
303
- find(spec, opts.merge(:limit => -1)).next_document
304
- end
305
-
306
- # Save a document to this collection.
307
- #
308
- # @param [Hash] doc
309
- # the document to be saved. If the document already has an '_id' key,
310
- # then an update (upsert) operation will be performed, and any existing
311
- # document with that _id is overwritten. Otherwise an insert operation is performed.
312
- #
313
- # @return [ObjectId] the _id of the saved document.
314
- #
315
- # @option opts [Hash] :w, :j, :wtimeout, :fsync Set the write concern for this operation.
316
- # :w > 0 will run a +getlasterror+ command on the database to report any assertion.
317
- # :j will confirm a write has been committed to the journal,
318
- # :wtimeout specifies how long to wait for write confirmation,
319
- # :fsync will confirm that a write has been fsynced.
320
- # Options provided here will override any write concern options set on this collection,
321
- # its database object, or the current connection. See the options
322
- # for DB#get_last_error.
323
- #
324
- # @raise [Mongo::OperationFailure] will be raised iff :w > 0 and the operation fails.
325
- def save(doc, opts={})
326
- if doc.has_key?(:_id) || doc.has_key?('_id')
327
- id = doc[:_id] || doc['_id']
328
- update({:_id => id}, doc, opts.merge!({:upsert => true}))
329
- id
330
- else
331
- insert(doc, opts)
332
- end
121
+ # Get the read concern for this collection instance.
122
+ #
123
+ # @example Get the read concern.
124
+ # collection.read_concern
125
+ #
126
+ # @return [ Hash ] The read concern.
127
+ #
128
+ # @since 2.2.0
129
+ def read_concern
130
+ options[:read_concern] || database.read_concern
333
131
  end
334
132
 
335
- # Insert one or more documents into the collection.
336
- #
337
- # @param [Hash, Array] doc_or_docs
338
- # a document (as a hash) or array of documents to be inserted.
339
- #
340
- # @return [ObjectId, Array]
341
- # The _id of the inserted document or a list of _ids of all inserted documents.
342
- # @return [[ObjectId, Array], [Hash, Array]]
343
- # 1st, the _id of the inserted document or a list of _ids of all inserted documents.
344
- # 2nd, a list of invalid documents.
345
- # Return this result format only when :collect_on_error is true.
346
- #
347
- # @option opts [String, Integer, Symbol] :w (1) Set default number of nodes to which a write
348
- # should be acknowledged
349
- # @option opts [Boolean] :j (false) Set journal acknowledgement
350
- # @option opts [Integer] :wtimeout (nil) Set replica set acknowledgement timeout
351
- # @option opts [Boolean] :fsync (false) Set fsync acknowledgement.
352
- #
353
- # Notes on write concern:
354
- # Options provided here will override any write concern options set on this collection,
355
- # its database object, or the current connection. See the options for +DB#get_last_error+.
356
- #
357
- # @option opts [Boolean] :continue_on_error (+false+) If true, then
358
- # continue a bulk insert even if one of the documents inserted
359
- # triggers a database assertion (as in a duplicate insert, for instance).
360
- # If not acknowledging writes, the list of ids returned will
361
- # include the object ids of all documents attempted on insert, even
362
- # if some are rejected on error. When acknowledging writes, any error will raise an
363
- # OperationFailure exception.
364
- # MongoDB v2.0+.
365
- # @option opts [Boolean] :collect_on_error (+false+) if true, then
366
- # collects invalid documents as an array. Note that this option changes the result format.
367
- #
368
- # @raise [Mongo::OperationFailure] will be raised iff :w > 0 and the operation fails.
369
- #
370
- # @core insert insert-instance_method
371
- def insert(doc_or_docs, opts={})
372
- doc_or_docs = [doc_or_docs] unless doc_or_docs.is_a?(Array)
373
- doc_or_docs.collect! { |doc| @pk_factory.create_pk(doc) }
374
- write_concern = get_write_concern(opts, self)
375
- result = insert_documents(doc_or_docs, @name, true, write_concern, opts)
376
- result.size > 1 ? result : result.first
133
+ # Get the server selector on this collection.
134
+ #
135
+ # @example Get the server selector.
136
+ # collection.server_selector
137
+ #
138
+ # @return [ Mongo::ServerSelector ] The server selector.
139
+ #
140
+ # @since 2.0.0
141
+ def server_selector
142
+ @server_selector ||= ServerSelector.get(read_preference || database.server_selector)
377
143
  end
378
- alias_method :<<, :insert
379
144
 
380
- # Remove all documents from this collection.
145
+ # Get the read preference on this collection.
381
146
  #
382
- # @param [Hash] selector
383
- # If specified, only matching documents will be removed.
147
+ # @example Get the read preference.
148
+ # collection.read_preference
384
149
  #
385
- # @option opts [String, Integer, Symbol] :w (1) Set default number of nodes to which a write
386
- # should be acknowledged
387
- # @option opts [Boolean] :j (false) Set journal acknowledgement
388
- # @option opts [Integer] :wtimeout (nil) Set replica set acknowledgement timeout
389
- # @option opts [Boolean] :fsync (false) Set fsync acknowledgement.
150
+ # @return [ Hash ] The read preference.
390
151
  #
391
- # Notes on write concern:
392
- # Options provided here will override any write concern options set on this collection,
393
- # its database object, or the current connection. See the options for +DB#get_last_error+.
152
+ # @since 2.0.0
153
+ def read_preference
154
+ @read_preference ||= options[:read] || database.read_preference
155
+ end
156
+
157
+ # Get the write concern on this collection.
394
158
  #
395
- # @example remove all documents from the 'users' collection:
396
- # users.remove
397
- # users.remove({})
159
+ # @example Get the write concern.
160
+ # collection.write_concern
398
161
  #
399
- # @example remove only documents that have expired:
400
- # users.remove({:expire => {"$lte" => Time.now}})
162
+ # @return [ Mongo::WriteConcern ] The write concern.
401
163
  #
402
- # @return [Hash, true] Returns a Hash containing the last error object if acknowledging writes
403
- # Otherwise, returns true.
164
+ # @since 2.0.0
165
+ def write_concern
166
+ @write_concern ||= WriteConcern.get(
167
+ options[:write_concern] || options[:write] || database.write_concern)
168
+ end
169
+
170
+ # Get the write concern for the collection, given the session.
404
171
  #
405
- # @raise [Mongo::OperationFailure] will be raised iff :w > 0 and the operation fails.
172
+ # If the session is in a transaction and the collection
173
+ # has an unacknowledged write concern, remove the write
174
+ # concern's :w option. Otherwise, return the unmodified
175
+ # write concern.
406
176
  #
407
- # @core remove remove-instance_method
408
- def remove(selector={}, opts={})
409
- write_concern = get_write_concern(opts, self)
410
- message = BSON::ByteBuffer.new("\0\0\0\0", @connection.max_message_size)
411
- BSON::BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{@name}")
412
- message.put_int(0)
413
- message.put_binary(BSON::BSON_CODER.serialize(selector, false, true, @connection.max_bson_size).to_s)
414
-
415
- instrument(:remove, :database => @db.name, :collection => @name, :selector => selector) do
416
- if Mongo::WriteConcern.gle?(write_concern)
417
- @connection.send_message_with_gle(Mongo::Constants::OP_DELETE, message, @db.name, nil, write_concern)
418
- else
419
- @connection.send_message(Mongo::Constants::OP_DELETE, message)
420
- true
177
+ # @return [ Mongo::WriteConcern ] The write concern.
178
+ #
179
+ # @api private
180
+ def write_concern_with_session(session)
181
+ wc = write_concern
182
+ if session && session.in_transaction?
183
+ if wc && !wc.acknowledged?
184
+ opts = wc.options.dup
185
+ opts.delete(:w)
186
+ return WriteConcern.get(opts)
421
187
  end
422
188
  end
189
+ wc
423
190
  end
424
191
 
425
- # Update one or more documents in this collection.
426
- #
427
- # @param [Hash] selector
428
- # a hash specifying elements which must be present for a document to be updated. Note:
429
- # the update command currently updates only the first document matching the
430
- # given selector. If you want all matching documents to be updated, be sure
431
- # to specify :multi => true.
432
- # @param [Hash] document
433
- # a hash specifying the fields to be changed in the selected document,
434
- # or (in the case of an upsert) the document to be inserted
435
- #
436
- # @option opts [Boolean] :upsert (+false+) if true, performs an upsert (update or insert)
437
- # @option opts [Boolean] :multi (+false+) update all documents matching the selector, as opposed to
438
- # just the first matching document. Note: only works in MongoDB 1.1.3 or later.
439
- # @option opts [String, Integer, Symbol] :w (1) Set default number of nodes to which a write
440
- # should be acknowledged
441
- # @option opts [Boolean] :j (false) Set journal acknowledgement
442
- # @option opts [Integer] :wtimeout (nil) Set replica set acknowledgement timeout
443
- # @option opts [Boolean] :fsync (false) Set fsync acknowledgement.
444
- #
445
- # Notes on write concern:
446
- # Options provided here will override any write concern options set on this collection,
447
- # its database object, or the current connection. See the options for DB#get_last_error.
448
- #
449
- # @return [Hash, true] Returns a Hash containing the last error object if acknowledging writes.
450
- # Otherwise, returns true.
451
- #
452
- # @raise [Mongo::OperationFailure] will be raised iff :w > 0 and the operation fails.
453
- #
454
- # @core update update-instance_method
455
- def update(selector, document, opts={})
456
- # Initial byte is 0.
457
- write_concern = get_write_concern(opts, self)
458
- message = BSON::ByteBuffer.new("\0\0\0\0", @connection.max_message_size)
459
- BSON::BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{@name}")
460
- update_options = 0
461
- update_options += 1 if opts[:upsert]
462
- update_options += 2 if opts[:multi]
463
-
464
- # Determine if update document has modifiers and check keys if so
465
- check_keys = document.keys.first.to_s.start_with?("$") ? false : true
466
-
467
- message.put_int(update_options)
468
- message.put_binary(BSON::BSON_CODER.serialize(selector, false, true, @connection.max_bson_size).to_s)
469
- message.put_binary(BSON::BSON_CODER.serialize(document, check_keys, true, @connection.max_bson_size).to_s)
192
+ # Provides a new collection with either a new read preference or new write concern
193
+ # merged over the existing read preference / write concern.
194
+ #
195
+ # @example Get a collection with a changed read preference.
196
+ # collection.with(read: { mode: :primary_preferred })
197
+ #
198
+ # @example Get a collection with a changed write concern.
199
+ # collection.with(write_concern: { w: 3 })
470
200
 
471
- instrument(:update, :database => @db.name, :collection => @name, :selector => selector, :document => document) do
472
- if Mongo::WriteConcern.gle?(write_concern)
473
- @connection.send_message_with_gle(Mongo::Constants::OP_UPDATE, message, @db.name, nil, write_concern)
474
- else
475
- @connection.send_message(Mongo::Constants::OP_UPDATE, message)
476
- end
201
+ # @param [ Hash ] new_options The new options to use.
202
+ #
203
+ # @return [ Mongo::Collection ] A new collection instance.
204
+ #
205
+ # @since 2.1.0
206
+ def with(new_options)
207
+ new_options.keys.each do |k|
208
+ raise Error::UnchangeableCollectionOption.new(k) unless CHANGEABLE_OPTIONS.include?(k)
477
209
  end
478
- end
479
-
480
- # Create a new index.
481
- #
482
- # @param [String, Array] spec
483
- # should be either a single field name or an array of
484
- # [field name, type] pairs. Index types should be specified
485
- # as Mongo::ASCENDING, Mongo::DESCENDING, Mongo::GEO2D, Mongo::GEO2DSPHERE, Mongo::GEOHAYSTACK,
486
- # Mongo::TEXT or Mongo::HASHED.
487
- #
488
- # Note that geospatial indexing only works with versions of MongoDB >= 1.3.3+. Keep in mind, too,
489
- # that in order to geo-index a given field, that field must reference either an array or a sub-object
490
- # where the first two values represent x- and y-coordinates. Examples can be seen below.
491
- #
492
- # Also note that it is permissible to create compound indexes that include a geospatial index as
493
- # long as the geospatial index comes first.
494
- #
495
- # If your code calls create_index frequently, you can use Collection#ensure_index to cache these calls
496
- # and thereby prevent excessive round trips to the database.
497
- #
498
- # @option opts [Boolean] :unique (false) if true, this index will enforce a uniqueness constraint.
499
- # @option opts [Boolean] :background (false) indicate that the index should be built in the background. This
500
- # feature is only available in MongoDB >= 1.3.2.
501
- # @option opts [Boolean] :drop_dups (nil) If creating a unique index on a collection with pre-existing records,
502
- # this option will keep the first document the database indexes and drop all subsequent with duplicate values.
503
- # @option opts [Integer] :bucket_size (nil) For use with geoHaystack indexes. Number of documents to group
504
- # together within a certain proximity to a given longitude and latitude.
505
- # @option opts [Integer] :min (nil) specify the minimum longitude and latitude for a geo index.
506
- # @option opts [Integer] :max (nil) specify the maximum longitude and latitude for a geo index.
507
- #
508
- # @example Creating a compound index using a hash: (Ruby 1.9+ Syntax)
509
- # @posts.create_index({'subject' => Mongo::ASCENDING, 'created_at' => Mongo::DESCENDING})
510
- #
511
- # @example Creating a compound index:
512
- # @posts.create_index([['subject', Mongo::ASCENDING], ['created_at', Mongo::DESCENDING]])
513
- #
514
- # @example Creating a geospatial index using a hash: (Ruby 1.9+ Syntax)
515
- # @restaurants.create_index(:location => Mongo::GEO2D)
516
- #
517
- # @example Creating a geospatial index:
518
- # @restaurants.create_index([['location', Mongo::GEO2D]])
519
- #
520
- # # Note that this will work only if 'location' represents x,y coordinates:
521
- # {'location': [0, 50]}
522
- # {'location': {'x' => 0, 'y' => 50}}
523
- # {'location': {'latitude' => 0, 'longitude' => 50}}
524
- #
525
- # @example A geospatial index with alternate longitude and latitude:
526
- # @restaurants.create_index([['location', Mongo::GEO2D]], :min => 500, :max => 500)
527
- #
528
- # @return [String] the name of the index created.
529
- #
530
- # @core indexes create_index-instance_method
531
- def create_index(spec, opts={})
532
- opts[:dropDups] = opts[:drop_dups] if opts[:drop_dups]
533
- opts[:bucketSize] = opts[:bucket_size] if opts[:bucket_size]
534
- field_spec = parse_index_spec(spec)
535
- opts = opts.dup
536
- name = opts.delete(:name) || generate_index_name(field_spec)
537
- name = name.to_s if name
538
- generate_indexes(field_spec, name, opts)
539
- name
540
- end
541
-
542
- # Calls create_index and sets a flag to not do so again for another X minutes.
543
- # this time can be specified as an option when initializing a Mongo::DB object as options[:cache_time]
544
- # Any changes to an index will be propagated through regardless of cache time (e.g., a change of index direction)
545
- #
546
- # The parameters and options for this methods are the same as those for Collection#create_index.
547
- #
548
- # @example Call sequence (Ruby 1.9+ Syntax):
549
- # Time t: @posts.ensure_index(:subject => Mongo::ASCENDING) -- calls create_index and
550
- # sets the 5 minute cache
551
- # Time t+2min : @posts.ensure_index(:subject => Mongo::ASCENDING) -- doesn't do anything
552
- # Time t+3min : @posts.ensure_index(:something_else => Mongo::ASCENDING) -- calls create_index
553
- # and sets 5 minute cache
554
- # Time t+10min : @posts.ensure_index(:subject => Mongo::ASCENDING) -- calls create_index and
555
- # resets the 5 minute counter
556
- #
557
- # @return [String] the name of the index.
558
- def ensure_index(spec, opts={})
559
- now = Time.now.utc.to_i
560
- opts[:dropDups] = opts[:drop_dups] if opts[:drop_dups]
561
- opts[:bucketSize] = opts[:bucket_size] if opts[:bucket_size]
562
- field_spec = parse_index_spec(spec)
563
- name = opts[:name] || generate_index_name(field_spec)
564
- name = name.to_s if name
565
-
566
- if !@cache[name] || @cache[name] <= now
567
- generate_indexes(field_spec, name, opts)
210
+ options = @options.dup
211
+ if options[:write] && new_options[:write_concern]
212
+ options.delete(:write)
568
213
  end
569
-
570
- # Reset the cache here in case there are any errors inserting. Best to be safe.
571
- @cache[name] = now + @cache_time
572
- name
214
+ if options[:write_concern] && new_options[:write]
215
+ options.delete(:write_concern)
216
+ end
217
+ Collection.new(database, name, options.update(new_options))
573
218
  end
574
219
 
575
- # Drop a specified index.
220
+ # Is the collection capped?
221
+ #
222
+ # @example Is the collection capped?
223
+ # collection.capped?
576
224
  #
577
- # @param [String] name
225
+ # @return [ true, false ] If the collection is capped.
578
226
  #
579
- # @core indexes
580
- def drop_index(name)
581
- if name.is_a?(Array)
582
- return drop_index(index_name(name))
227
+ # @since 2.0.0
228
+ def capped?
229
+ database.read_command(:collstats => name).documents[0][CAPPED]
230
+ end
231
+
232
+ # Force the collection to be created in the database.
233
+ #
234
+ # @example Force the collection to be created.
235
+ # collection.create
236
+ #
237
+ # @param [ Hash ] opts The options for the create operation.
238
+ #
239
+ # @option opts [ Session ] :session The session to use for the operation.
240
+ # @option opts [ Hash ] :write_concern The write concern options.
241
+ # @option opts [ Hash ] :time_series Create a time-series collection.
242
+ # @option opts [ Integer ] :expire_after Number indicating
243
+ # after how many seconds old time-series data should be deleted.
244
+ #
245
+ # @return [ Result ] The result of the command.
246
+ #
247
+ # @since 2.0.0
248
+ def create(opts = {})
249
+ # Passing read options to create command causes it to break.
250
+ # Filter the read options out.
251
+ # TODO put the list of read options in a class-level constant when
252
+ # we figure out what the full set of them is.
253
+ options = Hash[self.options.reject do |key, value|
254
+ %w(read read_preference).include?(key.to_s)
255
+ end]
256
+ options.update(Utils.slice_hash(opts, *TIME_SERIES_OPTIONS.keys))
257
+ # Converting Ruby spelled time series options to server style.
258
+ TIME_SERIES_OPTIONS.each do |ruby_key, server_key|
259
+ if options.key?(ruby_key)
260
+ options[server_key] = options.delete(ruby_key)
261
+ end
262
+ end
263
+ operation = { :create => name }.merge(options)
264
+ operation.delete(:write)
265
+ operation.delete(:write_concern)
266
+ client.send(:with_session, opts) do |session|
267
+ write_concern = if opts[:write_concern]
268
+ WriteConcern.get(opts[:write_concern])
269
+ else
270
+ self.write_concern
271
+ end
272
+ server = next_primary(nil, session)
273
+ if (options[:collation] || options[Operation::COLLATION]) && !server.with_connection { |connection| connection.features }.collation_enabled?
274
+ raise Error::UnsupportedCollation
275
+ end
276
+
277
+ Operation::Create.new({
278
+ selector: operation,
279
+ db_name: database.name,
280
+ write_concern: write_concern,
281
+ session: session,
282
+ }).execute(server, context: Operation::Context.new(client: client, session: session))
583
283
  end
584
- @cache[name.to_s] = nil
585
- @db.drop_index(@name, name)
586
284
  end
587
285
 
588
- # Drop all indexes.
286
+ # Drop the collection. Will also drop all indexes associated with the
287
+ # collection.
589
288
  #
590
- # @core indexes
591
- def drop_indexes
592
- @cache = {}
593
-
594
- # Note: calling drop_indexes with no args will drop them all.
595
- @db.drop_index(@name, '*')
289
+ # @note An error returned if the collection doesn't exist is suppressed.
290
+ #
291
+ # @example Drop the collection.
292
+ # collection.drop
293
+ #
294
+ # @param [ Hash ] opts The options for the drop operation.
295
+ #
296
+ # @option options [ Session ] :session The session to use for the operation.
297
+ # @option opts [ Hash ] :write_concern The write concern options.
298
+ #
299
+ # @return [ Result ] The result of the command.
300
+ #
301
+ # @since 2.0.0
302
+ def drop(opts = {})
303
+ client.send(:with_session, opts) do |session|
304
+ temp_write_concern = write_concern
305
+ write_concern = if opts[:write_concern]
306
+ WriteConcern.get(opts[:write_concern])
307
+ else
308
+ temp_write_concern
309
+ end
310
+ Operation::Drop.new({
311
+ selector: { :drop => name },
312
+ db_name: database.name,
313
+ write_concern: write_concern,
314
+ session: session,
315
+ }).execute(next_primary(nil, session), context: Operation::Context.new(client: client, session: session))
316
+ end
317
+ rescue Error::OperationFailure => ex
318
+ # NamespaceNotFound
319
+ if ex.code == 26 || ex.code.nil? && ex.message =~ /ns not found/
320
+ false
321
+ else
322
+ raise
323
+ end
324
+ end
325
+
326
+ # Find documents in the collection.
327
+ #
328
+ # @example Find documents in the collection by a selector.
329
+ # collection.find(name: 1)
330
+ #
331
+ # @example Get all documents in a collection.
332
+ # collection.find
333
+ #
334
+ # @param [ Hash ] filter The filter to use in the find.
335
+ # @param [ Hash ] options The options for the find.
336
+ #
337
+ # @option options [ true, false ] :allow_disk_use When set to true, the
338
+ # server can write temporary data to disk while executing the find
339
+ # operation. This option is only available on MongoDB server versions
340
+ # 4.4 and newer.
341
+ # @option options [ true, false ] :allow_partial_results Allows the query to get partial
342
+ # results if some shards are down.
343
+ # @option options [ Integer ] :batch_size The number of documents returned in each batch
344
+ # of results from MongoDB.
345
+ # @option options [ Hash ] :collation The collation to use.
346
+ # @option options [ String ] :comment Associate a comment with the query.
347
+ # @option options [ :tailable, :tailable_await ] :cursor_type The type of cursor to use.
348
+ # @option options [ Integer ] :limit The max number of docs to return from the query.
349
+ # @option options [ Integer ] :max_time_ms
350
+ # The maximum amount of time to allow the query to run, in milliseconds.
351
+ # @option options [ Hash ] :modifiers A document containing meta-operators modifying the
352
+ # output or behavior of a query.
353
+ # @option options [ true, false ] :no_cursor_timeout The server normally times out idle
354
+ # cursors after an inactivity period (10 minutes) to prevent excess memory use.
355
+ # Set this option to prevent that.
356
+ # @option options [ true, false ] :oplog_replay Internal replication use only - driver
357
+ # should not set.
358
+ # @option options [ Hash ] :projection The fields to include or exclude from each doc
359
+ # in the result set.
360
+ # @option options [ Session ] :session The session to use.
361
+ # @option options [ Integer ] :skip The number of docs to skip before returning results.
362
+ # @option options [ Hash ] :sort The key and direction pairs by which the result set
363
+ # will be sorted.
364
+ #
365
+ # @return [ CollectionView ] The collection view.
366
+ #
367
+ # @since 2.0.0
368
+ def find(filter = nil, options = {})
369
+ View.new(self, filter || {}, options)
370
+ end
371
+
372
+ # Perform an aggregation on the collection.
373
+ #
374
+ # @example Perform an aggregation.
375
+ # collection.aggregate([ { "$group" => { "_id" => "$city", "tpop" => { "$sum" => "$pop" }}} ])
376
+ #
377
+ # @param [ Array<Hash> ] pipeline The aggregation pipeline.
378
+ # @param [ Hash ] options The aggregation options.
379
+ #
380
+ # @option options [ true, false ] :allow_disk_use Set to true if disk
381
+ # usage is allowed during the aggregation.
382
+ # @option options [ Integer ] :batch_size The number of documents to return
383
+ # per batch.
384
+ # @option options [ true, false ] :bypass_document_validation Whether or
385
+ # not to skip document level validation.
386
+ # @option options [ Hash ] :collation The collation to use.
387
+ # @option options [ String ] :comment Associate a comment with the aggregation.
388
+ # @option options [ String ] :hint The index to use for the aggregation.
389
+ # @option options [ Integer ] :max_time_ms The maximum amount of time in
390
+ # milliseconds to allow the aggregation to run.
391
+ # @option options [ true, false ] :use_cursor Indicates whether the command
392
+ # will request that the server provide results using a cursor. Note that
393
+ # as of server version 3.6, aggregations always provide results using a
394
+ # cursor and this option is therefore not valid.
395
+ # @option options [ Session ] :session The session to use.
396
+ #
397
+ # @return [ Aggregation ] The aggregation object.
398
+ #
399
+ # @since 2.1.0
400
+ def aggregate(pipeline, options = {})
401
+ View.new(self, {}, options).aggregate(pipeline, options)
402
+ end
403
+
404
+ # As of version 3.6 of the MongoDB server, a ``$changeStream`` pipeline
405
+ # stage is supported in the aggregation framework. This stage allows users
406
+ # to request that notifications are sent for all changes to a particular
407
+ # collection.
408
+ #
409
+ # @example Get change notifications for a given collection.
410
+ # collection.watch([{ '$match' => { operationType: { '$in' => ['insert', 'replace'] } } }])
411
+ #
412
+ # @param [ Array<Hash> ] pipeline Optional additional filter operators.
413
+ # @param [ Hash ] options The change stream options.
414
+ #
415
+ # @option options [ String ] :full_document Allowed values: ‘default’,
416
+ # ‘updateLookup’. Defaults to ‘default’. When set to ‘updateLookup’,
417
+ # the change notification for partial updates will include both a delta
418
+ # describing the changes to the document, as well as a copy of the entire
419
+ # document that was changed from some time after the change occurred.
420
+ # @option options [ BSON::Document, Hash ] :resume_after Specifies the
421
+ # logical starting point for the new change stream.
422
+ # @option options [ Integer ] :max_await_time_ms The maximum amount of time
423
+ # for the server to wait on new documents to satisfy a change stream query.
424
+ # @option options [ Integer ] :batch_size The number of documents to return
425
+ # per batch.
426
+ # @option options [ BSON::Document, Hash ] :collation The collation to use.
427
+ # @option options [ Session ] :session The session to use.
428
+ # @option options [ BSON::Timestamp ] :start_at_operation_time Only return
429
+ # changes that occurred at or after the specified timestamp. Any command run
430
+ # against the server will return a cluster time that can be used here.
431
+ # Only recognized by server versions 4.0+.
432
+ #
433
+ # @note A change stream only allows 'majority' read concern.
434
+ # @note This helper method is preferable to running a raw aggregation with
435
+ # a $changeStream stage, for the purpose of supporting resumability.
436
+ #
437
+ # @return [ ChangeStream ] The change stream object.
438
+ #
439
+ # @since 2.5.0
440
+ def watch(pipeline = [], options = {})
441
+ View::ChangeStream.new(View.new(self, {}, options), pipeline, nil, options)
442
+ end
443
+
444
+ # Gets an estimated number of matching documents in the collection.
445
+ #
446
+ # @example Get the count.
447
+ # collection.count(name: 1)
448
+ #
449
+ # @param [ Hash ] filter A filter for matching documents.
450
+ # @param [ Hash ] options The count options.
451
+ #
452
+ # @option options [ Hash ] :hint The index to use.
453
+ # @option options [ Integer ] :limit The maximum number of documents to count.
454
+ # @option options [ Integer ] :max_time_ms The maximum amount of time to allow the command to run.
455
+ # @option options [ Integer ] :skip The number of documents to skip before counting.
456
+ # @option options [ Hash ] :read The read preference options.
457
+ # @option options [ Hash ] :collation The collation to use.
458
+ # @option options [ Session ] :session The session to use.
459
+ #
460
+ # @return [ Integer ] The document count.
461
+ #
462
+ # @since 2.1.0
463
+ #
464
+ # @deprecated Use #count_documents or estimated_document_count instead. However, note that the
465
+ # following operators will need to be substituted when switching to #count_documents:
466
+ # * $where should be replaced with $expr (only works on 3.6+)
467
+ # * $near should be replaced with $geoWithin with $center
468
+ # * $nearSphere should be replaced with $geoWithin with $centerSphere
469
+ def count(filter = nil, options = {})
470
+ View.new(self, filter || {}, options).count(options)
596
471
  end
597
472
 
598
- # Drop the entire collection. USE WITH CAUTION.
599
- def drop
600
- @db.drop_collection(@name)
473
+ # Gets the number of documents matching the query. Unlike the deprecated
474
+ # #count method, this will return the exact number of documents matching
475
+ # the filter (or exact number of documents in the collection, if no filter
476
+ # is provided) rather than an estimate.
477
+ #
478
+ # Use #estimated_document_count to retrieve an estimate of the number
479
+ # of documents in the collection using the collection metadata.
480
+ #
481
+ # @param [ Hash ] filter A filter for matching documents.
482
+ # @param [ Hash ] options Options for the operation.
483
+ #
484
+ # @option options :skip [ Integer ] The number of documents to skip.
485
+ # @option options :hint [ Hash ] Override default index selection and force
486
+ # MongoDB to use a specific index for the query. Requires server version 3.6+.
487
+ # @option options :limit [ Integer ] Max number of docs to count.
488
+ # @option options :max_time_ms [ Integer ] The maximum amount of time to allow the
489
+ # command to run.
490
+ # @option options :read [ Hash ] The read preference options.
491
+ # @option options :collation [ Hash ] The collation to use.
492
+ #
493
+ # @return [ Integer ] The document count.
494
+ #
495
+ # @since 2.6.0
496
+ def count_documents(filter = {}, options = {})
497
+ View.new(self, filter, options).count_documents(options)
601
498
  end
602
499
 
603
- # Atomically update and return a document using MongoDB's findAndModify command. (MongoDB > 1.3.0)
604
- #
605
- # @option opts [Hash] :query ({}) a query selector document for matching the desired document.
606
- # @option opts [Hash] :update (nil) the update operation to perform on the matched document.
607
- # @option opts [Array, String, OrderedHash] :sort ({}) specify a sort option for the query using any
608
- # of the sort options available for Cursor#sort. Sort order is important if the query will be matching
609
- # multiple documents since only the first matching document will be updated and returned.
610
- # @option opts [Boolean] :remove (false) If true, removes the the returned document from the collection.
611
- # @option opts [Boolean] :new (false) If true, returns the updated document; otherwise, returns the document
612
- # prior to update.
613
- #
614
- # @return [Hash] the matched document.
615
- #
616
- # @core findandmodify find_and_modify-instance_method
617
- def find_and_modify(opts={})
618
- cmd = BSON::OrderedHash.new
619
- cmd[:findandmodify] = @name
620
- cmd.merge!(opts)
621
- cmd[:sort] = Mongo::Support.format_order_clause(opts[:sort]) if opts[:sort]
622
-
623
- @db.command(cmd)['value']
500
+ # Gets an estimate of the number of documents in the collection using the
501
+ # collection metadata.
502
+ #
503
+ # Use #count_documents to retrieve the exact number of documents in the
504
+ # collection, or to count documents matching a filter.
505
+ #
506
+ # @param [ Hash ] options Options for the operation.
507
+ #
508
+ # @option opts :max_time_ms [ Integer ] The maximum amount of time to allow
509
+ # the command to run for on the server.
510
+ # @option opts [ Hash ] :read The read preference options.
511
+ #
512
+ # @return [ Integer ] The document count.
513
+ #
514
+ # @since 2.6.0
515
+ def estimated_document_count(options = {})
516
+ View.new(self, {}, options).estimated_document_count(options)
624
517
  end
625
518
 
626
- # Perform an aggregation using the aggregation framework on the current collection.
627
- # @note Aggregate requires server version >= 2.1.1
628
- # @note Field References: Within an expression, field names must be quoted and prefixed by a dollar sign ($).
519
+ # Get a list of distinct values for a specific field.
629
520
  #
630
- # @example Define the pipeline as an array of operator hashes:
631
- # coll.aggregate([ {"$project" => {"last_name" => 1, "first_name" => 1 }}, {"$match" => {"last_name" => "Jones"}} ])
521
+ # @example Get the distinct values.
522
+ # collection.distinct('name')
632
523
  #
633
- # @param [Array] pipeline Should be a single array of pipeline operator hashes.
524
+ # @param [ Symbol, String ] field_name The name of the field.
525
+ # @param [ Hash ] filter The documents from which to retrieve the distinct values.
526
+ # @param [ Hash ] options The distinct command options.
634
527
  #
635
- # '$project' Reshapes a document stream by including fields, excluding fields, inserting computed fields,
636
- # renaming fields,or creating/populating fields that hold sub-documents.
528
+ # @option options [ Integer ] :max_time_ms The maximum amount of time to allow the command to run.
529
+ # @option options [ Hash ] :read The read preference options.
530
+ # @option options [ Hash ] :collation The collation to use.
531
+ # @option options [ Session ] :session The session to use.
637
532
  #
638
- # '$match' Query-like interface for filtering documents out of the aggregation pipeline.
533
+ # @return [ Array<Object> ] The list of distinct values.
639
534
  #
640
- # '$limit' Restricts the number of documents that pass through the pipeline.
535
+ # @since 2.1.0
536
+ def distinct(field_name, filter = nil, options = {})
537
+ View.new(self, filter || {}, options).distinct(field_name, options)
538
+ end
539
+
540
+ # Get a view of all indexes for this collection. Can be iterated or has
541
+ # more operations.
641
542
  #
642
- # '$skip' Skips over the specified number of documents and passes the rest along the pipeline.
543
+ # @example Get the index view.
544
+ # collection.indexes
643
545
  #
644
- # '$unwind' Peels off elements of an array individually, returning one document for each member.
546
+ # @param [ Hash ] options Options for getting a list of all indexes.
645
547
  #
646
- # '$group' Groups documents for calculating aggregate values.
548
+ # @option options [ Session ] :session The session to use.
647
549
  #
648
- # '$sort' Sorts all input documents and returns them to the pipeline in sorted order.
550
+ # @return [ View::Index ] The index view.
649
551
  #
650
- # @option opts [:primary, :secondary] :read Read preference indicating which server to perform this query
651
- # on. See Collection#find for more details.
652
- # @option opts [String] :comment (nil) a comment to include in profiling logs
552
+ # @since 2.0.0
553
+ def indexes(options = {})
554
+ Index::View.new(self, options)
555
+ end
556
+
557
+ # Get a pretty printed string inspection for the collection.
653
558
  #
654
- # @return [Array] An Array with the aggregate command's results.
559
+ # @example Inspect the collection.
560
+ # collection.inspect
655
561
  #
656
- # @raise MongoArgumentError if operators either aren't supplied or aren't in the correct format.
657
- # @raise MongoOperationFailure if the aggregate command fails.
562
+ # @return [ String ] The collection inspection.
658
563
  #
659
- def aggregate(pipeline=nil, opts={})
660
- raise MongoArgumentError, "pipeline must be an array of operators" unless pipeline.class == Array
661
- raise MongoArgumentError, "pipeline operators must be hashes" unless pipeline.all? { |op| op.class == Hash }
662
-
663
- hash = BSON::OrderedHash.new
664
- hash['aggregate'] = self.name
665
- hash['pipeline'] = pipeline
666
-
667
- result = @db.command(hash, command_options(opts))
668
- unless Mongo::Support.ok?(result)
669
- raise Mongo::OperationFailure, "aggregate failed: #{result['errmsg']}"
670
- end
671
-
672
- return result["result"]
564
+ # @since 2.0.0
565
+ def inspect
566
+ "#<Mongo::Collection:0x#{object_id} namespace=#{namespace}>"
673
567
  end
674
568
 
675
- # Perform a map-reduce operation on the current collection.
676
- #
677
- # @param [String, BSON::Code] map a map function, written in JavaScript.
678
- # @param [String, BSON::Code] reduce a reduce function, written in JavaScript.
679
- #
680
- # @option opts [Hash] :query ({}) a query selector document, like what's passed to #find, to limit
681
- # the operation to a subset of the collection.
682
- # @option opts [Array] :sort ([]) an array of [key, direction] pairs to sort by. Direction should
683
- # be specified as Mongo::ASCENDING (or :ascending / :asc) or Mongo::DESCENDING (or :descending / :desc)
684
- # @option opts [Integer] :limit (nil) if passing a query, number of objects to return from the collection.
685
- # @option opts [String, BSON::Code] :finalize (nil) a javascript function to apply to the result set after the
686
- # map/reduce operation has finished.
687
- # @option opts [String] :out (nil) a valid output type. In versions of MongoDB prior to v1.7.6,
688
- # this option takes the name of a collection for the output results. In versions 1.7.6 and later,
689
- # this option specifies the output type. See the core docs for available output types.
690
- # @option opts [Boolean] :keeptemp (false) if true, the generated collection will be persisted. The default
691
- # is false. Note that this option has no effect is versions of MongoDB > v1.7.6.
692
- # @option opts [Boolean ] :verbose (false) if true, provides statistics on job execution time.
693
- # @option opts [Boolean] :raw (false) if true, return the raw result object from the map_reduce command, and not
694
- # the instantiated collection that's returned by default. Note if a collection name isn't returned in the
695
- # map-reduce output (as, for example, when using :out => { :inline => 1 }), then you must specify this option
696
- # or an ArgumentError will be raised.
697
- # @option opts [:primary, :secondary] :read Read preference indicating which server to run this map-reduce
698
- # on. See Collection#find for more details.
699
- # @option opts [String] :comment (nil) a comment to include in profiling logs
700
- #
701
- # @return [Collection, Hash] a Mongo::Collection object or a Hash with the map-reduce command's results.
702
- #
703
- # @raise ArgumentError if you specify { :out => { :inline => true }} but don't specify :raw => true.
704
- #
705
- # @see http://www.mongodb.org/display/DOCS/MapReduce Offical MongoDB map/reduce documentation.
706
- #
707
- # @core mapreduce map_reduce-instance_method
708
- def map_reduce(map, reduce, opts={})
709
- map = BSON::Code.new(map) unless map.is_a?(BSON::Code)
710
- reduce = BSON::Code.new(reduce) unless reduce.is_a?(BSON::Code)
711
- raw = opts.delete(:raw)
712
-
713
- hash = BSON::OrderedHash.new
714
- hash['mapreduce'] = self.name
715
- hash['map'] = map
716
- hash['reduce'] = reduce
717
- hash.merge! opts
718
- if hash[:sort]
719
- hash[:sort] = Mongo::Support.format_order_clause(hash[:sort])
720
- end
721
-
722
- result = @db.command(hash, command_options(opts))
723
- unless Mongo::Support.ok?(result)
724
- raise Mongo::OperationFailure, "map-reduce failed: #{result['errmsg']}"
725
- end
569
+ # Insert a single document into the collection.
570
+ #
571
+ # @example Insert a document into the collection.
572
+ # collection.insert_one({ name: 'test' })
573
+ #
574
+ # @param [ Hash ] document The document to insert.
575
+ # @param [ Hash ] opts The insert options.
576
+ #
577
+ # @option opts [ Session ] :session The session to use for the operation.
578
+ #
579
+ # @return [ Result ] The database response wrapper.
580
+ #
581
+ # @since 2.0.0
582
+ def insert_one(document, opts = {})
583
+ QueryCache.clear_namespace(namespace)
726
584
 
727
- if raw
728
- result
729
- elsif result["result"]
730
- if result['result'].is_a? BSON::OrderedHash and result['result'].has_key? 'db' and result['result'].has_key? 'collection'
731
- otherdb = @db.connection[result['result']['db']]
732
- otherdb[result['result']['collection']]
585
+ client.send(:with_session, opts) do |session|
586
+ write_concern = if opts[:write_concern]
587
+ WriteConcern.get(opts[:write_concern])
733
588
  else
734
- @db[result["result"]]
589
+ write_concern_with_session(session)
735
590
  end
736
- else
737
- raise ArgumentError, "Could not instantiate collection from result. If you specified " +
738
- "{:out => {:inline => true}}, then you must also specify :raw => true to get the results."
739
- end
740
- end
741
- alias :mapreduce :map_reduce
742
-
743
- # Perform a group aggregation.
744
- #
745
- # @param [Hash] opts the options for this group operation. The minimum required are :initial
746
- # and :reduce.
747
- #
748
- # @option opts [Array, String, Symbol] :key (nil) Either the name of a field or a list of fields to group by (optional).
749
- # @option opts [String, BSON::Code] :keyf (nil) A JavaScript function to be used to generate the grouping keys (optional).
750
- # @option opts [String, BSON::Code] :cond ({}) A document specifying a query for filtering the documents over
751
- # which the aggregation is run (optional).
752
- # @option opts [Hash] :initial the initial value of the aggregation counter object (required).
753
- # @option opts [String, BSON::Code] :reduce (nil) a JavaScript aggregation function (required).
754
- # @option opts [String, BSON::Code] :finalize (nil) a JavaScript function that receives and modifies
755
- # each of the resultant grouped objects. Available only when group is run with command
756
- # set to true.
757
- # @option opts [:primary, :secondary] :read Read preference indicating which server to perform this group
758
- # on. See Collection#find for more details.
759
- # @option opts [String] :comment (nil) a comment to include in profiling logs
760
- #
761
- # @return [Array] the command response consisting of grouped items.
762
- def group(opts, condition={}, initial={}, reduce=nil, finalize=nil)
763
- if opts.is_a?(Hash)
764
- return new_group(opts)
765
- else
766
- warn "Collection#group no longer take a list of parameters. This usage is deprecated and will be remove in v2.0." +
767
- "Check out the new API at http://api.mongodb.org/ruby/current/Mongo/Collection.html#group-instance_method"
768
- end
769
-
770
- reduce = BSON::Code.new(reduce) unless reduce.is_a?(BSON::Code)
771
-
772
- group_command = {
773
- "group" => {
774
- "ns" => @name,
775
- "$reduce" => reduce,
776
- "cond" => condition,
777
- "initial" => initial
778
- }
779
- }
780
-
781
- if opts.is_a?(Symbol)
782
- raise MongoArgumentError, "Group takes either an array of fields to group by or a JavaScript function" +
783
- "in the form of a String or BSON::Code."
784
- end
785
591
 
786
- unless opts.nil?
787
- if opts.is_a? Array
788
- key_type = "key"
789
- key_value = {}
790
- opts.each { |k| key_value[k] = 1 }
791
- else
792
- key_type = "$keyf"
793
- key_value = opts.is_a?(BSON::Code) ? opts : BSON::Code.new(opts)
592
+ if document.nil?
593
+ raise ArgumentError, "Document to be inserted cannot be nil"
794
594
  end
795
595
 
796
- group_command["group"][key_type] = key_value
797
- end
798
-
799
- finalize = BSON::Code.new(finalize) if finalize.is_a?(String)
800
- if finalize.is_a?(BSON::Code)
801
- group_command['group']['finalize'] = finalize
802
- end
803
-
804
- result = @db.command(group_command)
805
-
806
- if Mongo::Support.ok?(result)
807
- result["retval"]
808
- else
809
- raise OperationFailure, "group command failed: #{result['errmsg']}"
810
- end
811
- end
812
-
813
- private
814
-
815
- def new_group(opts={})
816
- reduce = opts[:reduce]
817
- finalize = opts[:finalize]
818
- cond = opts.fetch(:cond, {})
819
- initial = opts[:initial]
820
-
821
- if !(reduce && initial)
822
- raise MongoArgumentError, "Group requires at minimum values for initial and reduce."
823
- end
824
-
825
- cmd = {
826
- "group" => {
827
- "ns" => @name,
828
- "$reduce" => reduce.to_bson_code,
829
- "cond" => cond,
830
- "initial" => initial
831
- }
832
- }
833
-
834
- if finalize
835
- cmd['group']['finalize'] = finalize.to_bson_code
836
- end
837
-
838
- if key = opts[:key]
839
- if key.is_a?(String) || key.is_a?(Symbol)
840
- key = [key]
596
+ write_with_retry(session, write_concern) do |server, txn_num|
597
+ Operation::Insert.new(
598
+ :documents => [ document ],
599
+ :db_name => database.name,
600
+ :coll_name => name,
601
+ :write_concern => write_concern,
602
+ :bypass_document_validation => !!opts[:bypass_document_validation],
603
+ :options => opts,
604
+ :id_generator => client.options[:id_generator],
605
+ :session => session,
606
+ :txn_num => txn_num,
607
+ ).execute(server, context: Operation::Context.new(client: client, session: session))
841
608
  end
842
- key_value = {}
843
- key.each { |k| key_value[k] = 1 }
844
- cmd["group"]["key"] = key_value
845
- elsif keyf = opts[:keyf]
846
- cmd["group"]["$keyf"] = keyf.to_bson_code
847
609
  end
848
-
849
- result = @db.command(cmd, command_options(opts))
850
- result["retval"]
851
- end
852
-
853
- public
854
-
855
- # Return a list of distinct values for +key+ across all
856
- # documents in the collection. The key may use dot notation
857
- # to reach into an embedded object.
858
- #
859
- # @param [String, Symbol, OrderedHash] key or hash to group by.
860
- # @param [Hash] query a selector for limiting the result set over which to group.
861
- # @param [Hash] opts the options for this distinct operation.
862
- #
863
- # @option opts [:primary, :secondary] :read Read preference indicating which server to perform this query
864
- # on. See Collection#find for more details.
865
- # @option opts [String] :comment (nil) a comment to include in profiling logs
866
- #
867
- # @example Saving zip codes and ages and returning distinct results.
868
- # @collection.save({:zip => 10010, :name => {:age => 27}})
869
- # @collection.save({:zip => 94108, :name => {:age => 24}})
870
- # @collection.save({:zip => 10010, :name => {:age => 27}})
871
- # @collection.save({:zip => 99701, :name => {:age => 24}})
872
- # @collection.save({:zip => 94108, :name => {:age => 27}})
873
- #
874
- # @collection.distinct(:zip)
875
- # [10010, 94108, 99701]
876
- # @collection.distinct("name.age")
877
- # [27, 24]
878
- #
879
- # # You may also pass a document selector as the second parameter
880
- # # to limit the documents over which distinct is run:
881
- # @collection.distinct("name.age", {"name.age" => {"$gt" => 24}})
882
- # [27]
883
- #
884
- # @return [Array] an array of distinct values.
885
- def distinct(key, query=nil, opts={})
886
- raise MongoArgumentError unless [String, Symbol].include?(key.class)
887
- command = BSON::OrderedHash.new
888
- command[:distinct] = @name
889
- command[:key] = key.to_s
890
- command[:query] = query
891
-
892
- @db.command(command, command_options(opts))["values"]
893
610
  end
894
611
 
895
- # Rename this collection.
612
+ # Insert the provided documents into the collection.
896
613
  #
897
- # Note: If operating in auth mode, the client must be authorized as an admin to
898
- # perform this operation.
614
+ # @example Insert documents into the collection.
615
+ # collection.insert_many([{ name: 'test' }])
899
616
  #
900
- # @param [String] new_name the new name for this collection
617
+ # @param [ Array<Hash> ] documents The documents to insert.
618
+ # @param [ Hash ] options The insert options.
901
619
  #
902
- # @return [String] the name of the new collection.
620
+ # @option options [ true | false ] :ordered Whether the operations
621
+ # should be executed in order.
622
+ # @option options [ Session ] :session The session to use for the operation.
903
623
  #
904
- # @raise [Mongo::InvalidNSName] if +new_name+ is an invalid collection name.
905
- def rename(new_name)
906
- case new_name
907
- when Symbol, String
908
- else
909
- raise TypeError, "new_name must be a string or symbol"
910
- end
911
-
912
- new_name = new_name.to_s
913
-
914
- if new_name.empty? or new_name.include? ".."
915
- raise Mongo::InvalidNSName, "collection names cannot be empty"
916
- end
917
- if new_name.include? "$"
918
- raise Mongo::InvalidNSName, "collection names must not contain '$'"
919
- end
920
- if new_name.match(/^\./) or new_name.match(/\.$/)
921
- raise Mongo::InvalidNSName, "collection names must not start or end with '.'"
922
- end
624
+ # @return [ Result ] The database response wrapper.
625
+ #
626
+ # @since 2.0.0
627
+ def insert_many(documents, options = {})
628
+ QueryCache.clear_namespace(namespace)
923
629
 
924
- @db.rename_collection(@name, new_name)
925
- @name = new_name
630
+ inserts = documents.map{ |doc| { :insert_one => doc }}
631
+ bulk_write(inserts, options)
926
632
  end
927
633
 
928
- # Get information on the indexes for this collection.
634
+ # Execute a batch of bulk write operations.
929
635
  #
930
- # @return [Hash] a hash where the keys are index names.
636
+ # @example Execute a bulk write.
637
+ # collection.bulk_write(operations, options)
931
638
  #
932
- # @core indexes
933
- def index_information
934
- @db.index_information(@name)
639
+ # @param [ Array<Hash> ] requests The bulk write requests.
640
+ # @param [ Hash ] options The options.
641
+ #
642
+ # @option options [ true, false ] :ordered Whether the operations
643
+ # should be executed in order.
644
+ # @option options [ Hash ] :write_concern The write concern options.
645
+ # Can be :w => Integer, :fsync => Boolean, :j => Boolean.
646
+ # @option options [ true, false ] :bypass_document_validation Whether or
647
+ # not to skip document level validation.
648
+ # @option options [ Session ] :session The session to use for the set of operations.
649
+ #
650
+ # @return [ BulkWrite::Result ] The result of the operation.
651
+ #
652
+ # @since 2.0.0
653
+ def bulk_write(requests, options = {})
654
+ BulkWrite.new(self, requests, options).execute
935
655
  end
936
656
 
937
- # Return a hash containing options that apply to this collection.
938
- # For all possible keys and values, see DB#create_collection.
657
+ # Remove a document from the collection.
658
+ #
659
+ # @example Remove a single document from the collection.
660
+ # collection.delete_one
939
661
  #
940
- # @return [Hash] options that apply to this collection.
941
- def options
942
- @db.collections_info(@name).next_document['options']
662
+ # @param [ Hash ] filter The filter to use.
663
+ # @param [ Hash ] options The options.
664
+ #
665
+ # @option options [ Hash ] :collation The collation to use.
666
+ # @option options [ Session ] :session The session to use.
667
+ # @option options [ Hash | String ] :hint The index to use for this operation.
668
+ # May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
669
+ #
670
+ # @return [ Result ] The response from the database.
671
+ #
672
+ # @since 2.1.0
673
+ def delete_one(filter = nil, options = {})
674
+ find(filter, options).delete_one(options)
943
675
  end
944
676
 
945
- # Return stats on the collection. Uses MongoDB's collstats command.
677
+ # Remove documents from the collection.
678
+ #
679
+ # @example Remove multiple documents from the collection.
680
+ # collection.delete_many
946
681
  #
947
- # @return [Hash]
948
- def stats
949
- @db.command({:collstats => @name})
682
+ # @param [ Hash ] filter The filter to use.
683
+ # @param [ Hash ] options The options.
684
+ #
685
+ # @option options [ Hash ] :collation The collation to use.
686
+ # @option options [ Session ] :session The session to use.
687
+ # @option options [ Hash | String ] :hint The index to use for this operation.
688
+ # May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
689
+ #
690
+ # @return [ Result ] The response from the database.
691
+ #
692
+ # @since 2.1.0
693
+ def delete_many(filter = nil, options = {})
694
+ find(filter, options).delete_many(options)
950
695
  end
951
696
 
952
- # Get the number of documents in this collection.
953
- #
954
- # @option opts [Hash] :query ({}) A query selector for filtering the documents counted.
955
- # @option opts [Integer] :skip (nil) The number of documents to skip.
956
- # @option opts [Integer] :limit (nil) The number of documents to limit.
957
- # @option opts [:primary, :secondary] :read Read preference for this command. See Collection#find for
958
- # more details.
959
- # @option opts [String] :comment (nil) a comment to include in profiling logs
960
- #
961
- # @return [Integer]
962
- def count(opts={})
963
- find(opts[:query],
964
- :skip => opts[:skip],
965
- :limit => opts[:limit],
966
- :read => opts[:read],
967
- :comment => opts[:comment]).count(true)
697
+ # Execute a parallel scan on the collection view.
698
+ #
699
+ # Returns a list of up to cursor_count cursors that can be iterated concurrently.
700
+ # As long as the collection is not modified during scanning, each document appears once
701
+ # in one of the cursors' result sets.
702
+ #
703
+ # @example Execute a parallel collection scan.
704
+ # collection.parallel_scan(2)
705
+ #
706
+ # @param [ Integer ] cursor_count The max number of cursors to return.
707
+ # @param [ Hash ] options The parallel scan command options.
708
+ #
709
+ # @option options [ Integer ] :max_time_ms The maximum amount of time to allow the command
710
+ # to run in milliseconds.
711
+ # @option options [ Session ] :session The session to use.
712
+ #
713
+ # @return [ Array<Cursor> ] An array of cursors.
714
+ #
715
+ # @since 2.1
716
+ def parallel_scan(cursor_count, options = {})
717
+ find({}, options).send(:parallel_scan, cursor_count, options)
968
718
  end
969
719
 
970
- alias :size :count
971
-
972
- protected
973
-
974
- # Parse common options for read-only commands from an input @opts
975
- # hash and return a hash suitable for passing to DB#command.
976
- def command_options(opts)
977
- out = {}
978
-
979
- if read = opts[:read]
980
- Mongo::ReadPreference::validate(read)
981
- else
982
- read = @read
983
- end
984
- out[:read] = read
985
- out[:comment] = opts[:comment] if opts[:comment]
986
- out
720
+ # Replaces a single document in the collection with the new document.
721
+ #
722
+ # @example Replace a single document.
723
+ # collection.replace_one({ name: 'test' }, { name: 'test1' })
724
+ #
725
+ # @param [ Hash ] filter The filter to use.
726
+ # @param [ Hash ] replacement The replacement document..
727
+ # @param [ Hash ] options The options.
728
+ #
729
+ # @option options [ true, false ] :upsert Whether to upsert if the
730
+ # document doesn't exist.
731
+ # @option options [ true, false ] :bypass_document_validation Whether or
732
+ # not to skip document level validation.
733
+ # @option options [ Hash ] :collation The collation to use.
734
+ # @option options [ Session ] :session The session to use.
735
+ # @option options [ Hash | String ] :hint The index to use for this operation.
736
+ # May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
737
+ #
738
+ # @return [ Result ] The response from the database.
739
+ #
740
+ # @since 2.1.0
741
+ def replace_one(filter, replacement, options = {})
742
+ find(filter, options).replace_one(replacement, options)
987
743
  end
988
744
 
989
- def normalize_hint_fields(hint)
990
- case hint
991
- when String
992
- {hint => 1}
993
- when Hash
994
- hint
995
- when nil
996
- nil
997
- else
998
- h = BSON::OrderedHash.new
999
- hint.to_a.each { |k| h[k] = 1 }
1000
- h
1001
- end
745
+ # Update documents in the collection.
746
+ #
747
+ # @example Update multiple documents in the collection.
748
+ # collection.update_many({ name: 'test'}, '$set' => { name: 'test1' })
749
+ #
750
+ # @param [ Hash ] filter The filter to use.
751
+ # @param [ Hash | Array<Hash> ] update The update document or pipeline.
752
+ # @param [ Hash ] options The options.
753
+ #
754
+ # @option options [ true, false ] :upsert Whether to upsert if the
755
+ # document doesn't exist.
756
+ # @option options [ true, false ] :bypass_document_validation Whether or
757
+ # not to skip document level validation.
758
+ # @option options [ Hash ] :collation The collation to use.
759
+ # @option options [ Array ] :array_filters A set of filters specifying to which array elements
760
+ # an update should apply.
761
+ # @option options [ Session ] :session The session to use.
762
+ # @option options [ Hash | String ] :hint The index to use for this operation.
763
+ # May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
764
+ #
765
+ # @return [ Result ] The response from the database.
766
+ #
767
+ # @since 2.1.0
768
+ def update_many(filter, update, options = {})
769
+ find(filter, options).update_many(update, options)
1002
770
  end
1003
771
 
1004
- private
1005
-
1006
- def index_name(spec)
1007
- field_spec = parse_index_spec(spec)
1008
- index_information.each do |index|
1009
- return index[0] if index[1]['key'] == field_spec
1010
- end
1011
- nil
772
+ # Update a single document in the collection.
773
+ #
774
+ # @example Update a single document in the collection.
775
+ # collection.update_one({ name: 'test'}, '$set' => { name: 'test1'})
776
+ #
777
+ # @param [ Hash ] filter The filter to use.
778
+ # @param [ Hash | Array<Hash> ] update The update document or pipeline.
779
+ # @param [ Hash ] options The options.
780
+ #
781
+ # @option options [ true, false ] :upsert Whether to upsert if the
782
+ # document doesn't exist.
783
+ # @option options [ true, false ] :bypass_document_validation Whether or
784
+ # not to skip document level validation.
785
+ # @option options [ Hash ] :collation The collation to use.
786
+ # @option options [ Array ] :array_filters A set of filters specifying to which array elements
787
+ # an update should apply.
788
+ # @option options [ Session ] :session The session to use.
789
+ # @option options [ Hash | String ] :hint The index to use for this operation.
790
+ # May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
791
+ #
792
+ # @return [ Result ] The response from the database.
793
+ #
794
+ # @since 2.1.0
795
+ def update_one(filter, update, options = {})
796
+ find(filter, options).update_one(update, options)
1012
797
  end
1013
798
 
1014
- def parse_index_spec(spec)
1015
- field_spec = BSON::OrderedHash.new
1016
- if spec.is_a?(String) || spec.is_a?(Symbol)
1017
- field_spec[spec.to_s] = 1
1018
- elsif spec.is_a?(Hash)
1019
- if RUBY_VERSION < '1.9' && !spec.is_a?(BSON::OrderedHash)
1020
- raise MongoArgumentError, "Must use OrderedHash in Ruby < 1.9.0"
1021
- end
1022
- validate_index_types(spec.values)
1023
- field_spec = spec.is_a?(BSON::OrderedHash) ? spec : BSON::OrderedHash.try_convert(spec)
1024
- elsif spec.is_a?(Array) && spec.all? {|field| field.is_a?(Array) }
1025
- spec.each do |f|
1026
- validate_index_types(f[1])
1027
- field_spec[f[0].to_s] = f[1]
1028
- end
1029
- else
1030
- raise MongoArgumentError, "Invalid index specification #{spec.inspect}; " +
1031
- "should be either a hash (OrderedHash), string, symbol, or an array of arrays."
1032
- end
1033
- field_spec
799
+ # Finds a single document in the database via findAndModify and deletes
800
+ # it, returning the original document.
801
+ #
802
+ # @example Find one document and delete it.
803
+ # collection.find_one_and_delete(name: 'test')
804
+ #
805
+ # @param [ Hash ] filter The filter to use.
806
+ # @param [ Hash ] options The options.
807
+ #
808
+ # @option options [ Integer ] :max_time_ms The maximum amount of time to allow the command
809
+ # to run in milliseconds.
810
+ # @option options [ Hash ] :projection The fields to include or exclude in the returned doc.
811
+ # @option options [ Hash ] :sort The key and direction pairs by which the result set
812
+ # will be sorted.
813
+ # @option options [ Hash ] :write_concern The write concern options.
814
+ # Defaults to the collection's write concern.
815
+ # @option options [ Hash ] :collation The collation to use.
816
+ # @option options [ Session ] :session The session to use.
817
+ # @option options [ Hash | String ] :hint The index to use for this operation.
818
+ # May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
819
+ #
820
+ # @return [ BSON::Document, nil ] The document, if found.
821
+ #
822
+ # @since 2.1.0
823
+ def find_one_and_delete(filter, options = {})
824
+ find(filter, options).find_one_and_delete(options)
1034
825
  end
1035
826
 
1036
- def validate_index_types(*types)
1037
- types.flatten!
1038
- types.each do |t|
1039
- unless Mongo::INDEX_TYPES.values.include?(t)
1040
- raise MongoArgumentError, "Invalid index field #{t.inspect}; " +
1041
- "should be one of " + Mongo::INDEX_TYPES.map {|k,v| "Mongo::#{k} (#{v})"}.join(', ')
1042
- end
1043
- end
827
+ # Finds a single document via findAndModify and updates it, returning the original doc unless
828
+ # otherwise specified.
829
+ #
830
+ # @example Find a document and update it, returning the original.
831
+ # collection.find_one_and_update({ name: 'test' }, { "$set" => { name: 'test1' }})
832
+ #
833
+ # @example Find a document and update it, returning the updated document.
834
+ # collection.find_one_and_update({ name: 'test' }, { "$set" => { name: 'test1' }}, :return_document => :after)
835
+ #
836
+ # @param [ Hash ] filter The filter to use.
837
+ # @param [ Hash | Array<Hash> ] update The update document or pipeline.
838
+ # @param [ Hash ] options The options.
839
+ #
840
+ # @option options [ Integer ] :max_time_ms The maximum amount of time to allow the command
841
+ # to run in milliseconds.
842
+ # @option options [ Hash ] :projection The fields to include or exclude in the returned doc.
843
+ # @option options [ Hash ] :sort The key and direction pairs by which the result set
844
+ # will be sorted.
845
+ # @option options [ Symbol ] :return_document Either :before or :after.
846
+ # @option options [ true, false ] :upsert Whether to upsert if the document doesn't exist.
847
+ # @option options [ true, false ] :bypass_document_validation Whether or
848
+ # not to skip document level validation.
849
+ # @option options [ Hash ] :write_concern The write concern options.
850
+ # Defaults to the collection's write concern.
851
+ # @option options [ Hash ] :collation The collation to use.
852
+ # @option options [ Array ] :array_filters A set of filters specifying to which array elements
853
+ # an update should apply.
854
+ # @option options [ Session ] :session The session to use.
855
+ # @option options [ Hash | String ] :hint The index to use for this operation.
856
+ # May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
857
+ #
858
+ # @return [ BSON::Document ] The document.
859
+ #
860
+ # @since 2.1.0
861
+ def find_one_and_update(filter, update, options = {})
862
+ find(filter, options).find_one_and_update(update, options)
1044
863
  end
1045
864
 
1046
- def generate_indexes(field_spec, name, opts)
1047
- selector = {
1048
- :name => name,
1049
- :ns => "#{@db.name}.#{@name}",
1050
- :key => field_spec
1051
- }
1052
- selector.merge!(opts)
1053
-
1054
- begin
1055
- insert_documents([selector], Mongo::DB::SYSTEM_INDEX_COLLECTION, false, {:w => 1})
1056
-
1057
- rescue Mongo::OperationFailure => e
1058
- if selector[:dropDups] && e.message =~ /^11000/
1059
- # NOP. If the user is intentionally dropping dups, we can ignore duplicate key errors.
1060
- else
1061
- raise Mongo::OperationFailure, "Failed to create index #{selector.inspect} with the following error: " +
1062
- "#{e.message}"
1063
- end
1064
- end
1065
-
1066
- nil
865
+ # Finds a single document and replaces it, returning the original doc unless
866
+ # otherwise specified.
867
+ #
868
+ # @example Find a document and replace it, returning the original.
869
+ # collection.find_one_and_replace({ name: 'test' }, { name: 'test1' })
870
+ #
871
+ # @example Find a document and replace it, returning the new document.
872
+ # collection.find_one_and_replace({ name: 'test' }, { name: 'test1' }, :return_document => :after)
873
+ #
874
+ # @param [ Hash ] filter The filter to use.
875
+ # @param [ BSON::Document ] replacement The replacement document.
876
+ # @param [ Hash ] options The options.
877
+ #
878
+ # @option options [ Integer ] :max_time_ms The maximum amount of time to allow the command
879
+ # to run in milliseconds.
880
+ # @option options [ Hash ] :projection The fields to include or exclude in the returned doc.
881
+ # @option options [ Hash ] :sort The key and direction pairs by which the result set
882
+ # will be sorted.
883
+ # @option options [ Symbol ] :return_document Either :before or :after.
884
+ # @option options [ true, false ] :upsert Whether to upsert if the document doesn't exist.
885
+ # @option options [ true, false ] :bypass_document_validation Whether or
886
+ # not to skip document level validation.
887
+ # @option options [ Hash ] :write_concern The write concern options.
888
+ # Defaults to the collection's write concern.
889
+ # @option options [ Hash ] :collation The collation to use.
890
+ # @option options [ Session ] :session The session to use.
891
+ # @option options [ Hash | String ] :hint The index to use for this operation.
892
+ # May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
893
+ #
894
+ # @return [ BSON::Document ] The document.
895
+ #
896
+ # @since 2.1.0
897
+ def find_one_and_replace(filter, replacement, options = {})
898
+ find(filter, options).find_one_and_update(replacement, options)
1067
899
  end
1068
900
 
1069
- # Sends a Mongo::Constants::OP_INSERT message to the database.
1070
- # Takes an array of +documents+, an optional +collection_name+, and a
1071
- # +check_keys+ setting.
1072
- def insert_documents(documents, collection_name=@name, check_keys=true, write_concern={}, flags={})
1073
- message = BSON::ByteBuffer.new("", @connection.max_message_size)
1074
- if flags[:continue_on_error]
1075
- message.put_int(1)
1076
- else
1077
- message.put_int(0)
1078
- end
1079
-
1080
- collect_on_error = !!flags[:collect_on_error]
1081
- error_docs = [] if collect_on_error
1082
-
1083
- BSON::BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{collection_name}")
1084
- documents =
1085
- if collect_on_error
1086
- documents.select do |doc|
1087
- begin
1088
- message.put_binary(BSON::BSON_CODER.serialize(doc, check_keys, true, @connection.max_bson_size).to_s)
1089
- true
1090
- rescue StandardError # StandardError will be replaced with BSONError
1091
- doc.delete(:_id)
1092
- error_docs << doc
1093
- false
1094
- end
1095
- end
1096
- else
1097
- documents.each do |doc|
1098
- message.put_binary(BSON::BSON_CODER.serialize(doc, check_keys, true, @connection.max_bson_size).to_s)
1099
- end
1100
- end
1101
-
1102
- if message.size > @connection.max_message_size
1103
- raise InvalidOperation, "Exceded maximum insert size of #{@connection.max_message_size} bytes"
1104
- end
1105
-
1106
- instrument(:insert, :database => @db.name, :collection => collection_name, :documents => documents) do
1107
- if Mongo::WriteConcern.gle?(write_concern)
1108
- @connection.send_message_with_gle(Mongo::Constants::OP_INSERT, message, @db.name, nil, write_concern)
1109
- else
1110
- @connection.send_message(Mongo::Constants::OP_INSERT, message)
1111
- end
1112
- end
1113
-
1114
- doc_ids = documents.collect { |o| o[:_id] || o['_id'] }
1115
- if collect_on_error
1116
- return doc_ids, error_docs
1117
- else
1118
- doc_ids
1119
- end
901
+ # Get the fully qualified namespace of the collection.
902
+ #
903
+ # @example Get the fully qualified namespace.
904
+ # collection.namespace
905
+ #
906
+ # @return [ String ] The collection namespace.
907
+ #
908
+ # @since 2.0.0
909
+ def namespace
910
+ "#{database.name}.#{name}"
1120
911
  end
1121
912
 
1122
- def generate_index_name(spec)
1123
- indexes = []
1124
- spec.each_pair do |field, type|
1125
- indexes.push("#{field}_#{type}")
1126
- end
1127
- indexes.join("_")
913
+ # Whether the collection is a system collection.
914
+ #
915
+ # @return [ Boolean ] Whether the system is a system collection.
916
+ #
917
+ # @api private
918
+ def system_collection?
919
+ name.start_with?('system.')
1128
920
  end
1129
921
  end
1130
-
1131
922
  end