mongo 2.5.1 → 2.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +3 -2
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +1 -1
  5. data/lib/mongo/auth/user/view.rb +4 -4
  6. data/lib/mongo/bulk_write.rb +14 -19
  7. data/lib/mongo/cluster.rb +4 -2
  8. data/lib/mongo/cluster/app_metadata.rb +1 -1
  9. data/lib/mongo/cluster/reapers/cursor_reaper.rb +1 -1
  10. data/lib/mongo/collection.rb +13 -13
  11. data/lib/mongo/collection/view.rb +2 -1
  12. data/lib/mongo/collection/view/aggregation.rb +1 -1
  13. data/lib/mongo/collection/view/change_stream.rb +1 -1
  14. data/lib/mongo/collection/view/iterable.rb +4 -4
  15. data/lib/mongo/collection/view/map_reduce.rb +3 -3
  16. data/lib/mongo/collection/view/readable.rb +26 -20
  17. data/lib/mongo/collection/view/writable.rb +12 -12
  18. data/lib/mongo/cursor.rb +4 -7
  19. data/lib/mongo/database.rb +2 -2
  20. data/lib/mongo/database/view.rb +1 -1
  21. data/lib/mongo/grid/stream/write.rb +1 -1
  22. data/lib/mongo/index/view.rb +3 -3
  23. data/lib/mongo/operation.rb +38 -24
  24. data/lib/mongo/operation/aggregate.rb +53 -0
  25. data/lib/mongo/operation/aggregate/command.rb +59 -0
  26. data/lib/mongo/operation/aggregate/op_msg.rb +54 -0
  27. data/lib/mongo/operation/aggregate/result.rb +87 -0
  28. data/lib/mongo/operation/collections_info.rb +62 -0
  29. data/lib/mongo/operation/collections_info/result.rb +39 -0
  30. data/lib/mongo/operation/{executable.rb → command.rb} +16 -13
  31. data/lib/mongo/operation/command/command.rb +38 -0
  32. data/lib/mongo/operation/command/op_msg.rb +53 -0
  33. data/lib/mongo/operation/count.rb +48 -0
  34. data/lib/mongo/operation/count/command.rb +38 -0
  35. data/lib/mongo/operation/count/op_msg.rb +38 -0
  36. data/lib/mongo/operation/create.rb +48 -0
  37. data/lib/mongo/operation/create/command.rb +38 -0
  38. data/lib/mongo/operation/create/op_msg.rb +37 -0
  39. data/lib/mongo/operation/create_index.rb +48 -0
  40. data/lib/mongo/operation/create_index/command.rb +42 -0
  41. data/lib/mongo/operation/create_index/op_msg.rb +41 -0
  42. data/lib/mongo/operation/create_user.rb +48 -0
  43. data/lib/mongo/operation/{commands → create_user}/command.rb +13 -19
  44. data/lib/mongo/operation/create_user/op_msg.rb +41 -0
  45. data/lib/mongo/operation/delete.rb +38 -0
  46. data/lib/mongo/operation/delete/bulk_result.rb +46 -0
  47. data/lib/mongo/operation/delete/command.rb +59 -0
  48. data/lib/mongo/operation/delete/legacy.rb +69 -0
  49. data/lib/mongo/operation/delete/op_msg.rb +60 -0
  50. data/lib/mongo/operation/{write/delete → delete}/result.rb +18 -16
  51. data/lib/mongo/operation/distinct.rb +48 -0
  52. data/lib/mongo/operation/distinct/command.rb +38 -0
  53. data/lib/mongo/operation/distinct/op_msg.rb +38 -0
  54. data/lib/mongo/operation/drop.rb +48 -0
  55. data/lib/mongo/operation/drop/command.rb +38 -0
  56. data/lib/mongo/operation/{commands/count.rb → drop/op_msg.rb} +16 -6
  57. data/lib/mongo/operation/drop_database.rb +48 -0
  58. data/lib/mongo/operation/drop_database/command.rb +38 -0
  59. data/lib/mongo/operation/drop_database/op_msg.rb +37 -0
  60. data/lib/mongo/operation/drop_index.rb +48 -0
  61. data/lib/mongo/operation/drop_index/command.rb +42 -0
  62. data/lib/mongo/operation/{limited.rb → drop_index/op_msg.rb} +19 -15
  63. data/lib/mongo/operation/explain.rb +52 -0
  64. data/lib/mongo/operation/explain/command.rb +54 -0
  65. data/lib/mongo/operation/explain/legacy.rb +53 -0
  66. data/lib/mongo/operation/explain/op_msg.rb +54 -0
  67. data/lib/mongo/operation/explain/result.rb +50 -0
  68. data/lib/mongo/operation/find.rb +52 -0
  69. data/lib/mongo/operation/find/command.rb +54 -0
  70. data/lib/mongo/operation/find/legacy.rb +55 -0
  71. data/lib/mongo/operation/{read/query → find/legacy}/result.rb +3 -3
  72. data/lib/mongo/operation/find/op_msg.rb +59 -0
  73. data/lib/mongo/operation/find/result.rb +60 -0
  74. data/lib/mongo/operation/{commands/users_info/result.rb → get_more.rb} +20 -22
  75. data/lib/mongo/operation/get_more/command.rb +54 -0
  76. data/lib/mongo/operation/{commands/find.rb → get_more/legacy.rb} +15 -8
  77. data/lib/mongo/operation/get_more/op_msg.rb +58 -0
  78. data/lib/mongo/operation/get_more/result.rb +60 -0
  79. data/lib/mongo/operation/indexes.rb +52 -0
  80. data/lib/mongo/operation/indexes/command.rb +54 -0
  81. data/lib/mongo/operation/indexes/legacy.rb +57 -0
  82. data/lib/mongo/operation/indexes/op_msg.rb +54 -0
  83. data/lib/mongo/operation/indexes/result.rb +97 -0
  84. data/lib/mongo/operation/insert.rb +40 -0
  85. data/lib/mongo/operation/insert/bulk_result.rb +70 -0
  86. data/lib/mongo/operation/insert/command.rb +65 -0
  87. data/lib/mongo/operation/insert/legacy.rb +72 -0
  88. data/lib/mongo/operation/insert/op_msg.rb +61 -0
  89. data/lib/mongo/operation/insert/result.rb +64 -0
  90. data/lib/mongo/operation/kill_cursors.rb +25 -14
  91. data/lib/mongo/operation/{takes_write_concern.rb → kill_cursors/command.rb} +14 -12
  92. data/lib/mongo/operation/kill_cursors/legacy.rb +37 -0
  93. data/lib/mongo/operation/kill_cursors/op_msg.rb +37 -0
  94. data/lib/mongo/operation/list_collections.rb +49 -0
  95. data/lib/mongo/operation/list_collections/command.rb +60 -0
  96. data/lib/mongo/operation/list_collections/op_msg.rb +53 -0
  97. data/lib/mongo/operation/list_collections/result.rb +92 -0
  98. data/lib/mongo/operation/map_reduce.rb +49 -0
  99. data/lib/mongo/operation/map_reduce/command.rb +55 -0
  100. data/lib/mongo/operation/map_reduce/op_msg.rb +54 -0
  101. data/lib/mongo/operation/map_reduce/result.rb +129 -0
  102. data/lib/mongo/operation/parallel_scan.rb +49 -0
  103. data/lib/mongo/operation/parallel_scan/command.rb +67 -0
  104. data/lib/mongo/operation/parallel_scan/op_msg.rb +61 -0
  105. data/lib/mongo/operation/parallel_scan/result.rb +61 -0
  106. data/lib/mongo/operation/remove_user.rb +48 -0
  107. data/lib/mongo/operation/remove_user/command.rb +42 -0
  108. data/lib/mongo/operation/remove_user/op_msg.rb +41 -0
  109. data/lib/mongo/operation/result.rb +3 -1
  110. data/lib/mongo/operation/shared/bypass_document_validation.rb +36 -0
  111. data/lib/mongo/operation/{causally_consistent.rb → shared/causal_consistency_supported.rb} +5 -5
  112. data/lib/mongo/operation/shared/executable.rb +45 -0
  113. data/lib/mongo/operation/shared/idable.rb +64 -0
  114. data/lib/mongo/operation/{commands/distinct.rb → shared/limited.rb} +10 -7
  115. data/lib/mongo/operation/{object_id_generator.rb → shared/object_id_generator.rb} +2 -2
  116. data/lib/mongo/operation/{read_preference.rb → shared/read_preference_supported.rb} +14 -24
  117. data/lib/mongo/operation/shared/result/aggregatable.rb +75 -0
  118. data/lib/mongo/operation/shared/sessions_supported.rb +79 -0
  119. data/lib/mongo/operation/{specifiable.rb → shared/specifiable.rb} +40 -4
  120. data/lib/mongo/operation/shared/write.rb +81 -0
  121. data/lib/mongo/operation/shared/write_concern_supported.rb +39 -0
  122. data/lib/mongo/operation/update.rb +38 -0
  123. data/lib/mongo/operation/update/bulk_result.rb +126 -0
  124. data/lib/mongo/operation/update/command.rb +60 -0
  125. data/lib/mongo/operation/update/legacy.rb +80 -0
  126. data/lib/mongo/operation/{write/update → update/legacy}/result.rb +4 -82
  127. data/lib/mongo/operation/update/op_msg.rb +60 -0
  128. data/lib/mongo/operation/update/result.rb +102 -0
  129. data/lib/mongo/operation/update_user.rb +48 -0
  130. data/lib/mongo/operation/update_user/command.rb +41 -0
  131. data/lib/mongo/operation/update_user/op_msg.rb +41 -0
  132. data/lib/mongo/operation/users_info.rb +49 -0
  133. data/lib/mongo/operation/users_info/command.rb +58 -0
  134. data/lib/mongo/operation/users_info/op_msg.rb +57 -0
  135. data/lib/mongo/operation/{commands/collections_info → users_info}/result.rb +18 -17
  136. data/lib/mongo/server.rb +3 -5
  137. data/lib/mongo/server/connectable.rb +3 -3
  138. data/lib/mongo/server/connection.rb +14 -0
  139. data/lib/mongo/server_selector.rb +1 -1
  140. data/lib/mongo/server_selector/selectable.rb +3 -12
  141. data/lib/mongo/session.rb +13 -1
  142. data/lib/mongo/session/session_pool.rb +1 -1
  143. data/lib/mongo/version.rb +1 -1
  144. data/spec/mongo/client_spec.rb +15 -22
  145. data/spec/mongo/cluster/app_metadata_spec.rb +19 -3
  146. data/spec/mongo/cluster/cursor_reaper_spec.rb +37 -0
  147. data/spec/mongo/cluster_spec.rb +2 -2
  148. data/spec/mongo/collection/view/change_stream_spec.rb +2 -2
  149. data/spec/mongo/collection_spec.rb +105 -14
  150. data/spec/mongo/cursor_spec.rb +11 -11
  151. data/spec/mongo/grid/fs_bucket_spec.rb +5 -0
  152. data/spec/mongo/max_staleness_spec.rb +3 -1
  153. data/spec/mongo/operation/{commands/aggregate → aggregate}/result_spec.rb +1 -1
  154. data/spec/mongo/operation/{commands/aggregate_spec.rb → aggregate_spec.rb} +1 -1
  155. data/spec/mongo/operation/{commands/collections_info_spec.rb → collections_info_spec.rb} +4 -2
  156. data/spec/mongo/operation/{commands/command_spec.rb → command_spec.rb} +1 -1
  157. data/spec/mongo/operation/{write/command/create_index_spec.rb → create_index_spec.rb} +1 -1
  158. data/spec/mongo/operation/{write/create_user_spec.rb → create_user_spec.rb} +1 -1
  159. data/spec/mongo/operation/{write/bulk/delete_spec.rb → delete/bulk_spec.rb} +8 -8
  160. data/spec/mongo/operation/delete/command_spec.rb +111 -0
  161. data/spec/mongo/operation/{write/command/delete_spec.rb → delete/op_msg_spec.rb} +40 -34
  162. data/spec/mongo/operation/{write/delete_spec.rb → delete_spec.rb} +7 -7
  163. data/spec/mongo/operation/{write/command/drop_index_spec.rb → drop_index_spec.rb} +1 -1
  164. data/spec/mongo/operation/{read/query_spec.rb → find/legacy_spec.rb} +2 -2
  165. data/spec/mongo/operation/{read/get_more_spec.rb → get_more_spec.rb} +3 -3
  166. data/spec/mongo/operation/{commands/indexes_spec.rb → indexes_spec.rb} +6 -4
  167. data/spec/mongo/operation/{write/bulk/insert_spec.rb → insert/bulk_spec.rb} +9 -9
  168. data/spec/mongo/operation/insert/command_spec.rb +110 -0
  169. data/spec/mongo/operation/{write/command/insert_spec.rb → insert/op_msg_spec.rb} +51 -41
  170. data/spec/mongo/operation/{write/insert_spec.rb → insert_spec.rb} +2 -2
  171. data/spec/mongo/operation/kill_cursors_spec.rb +2 -2
  172. data/spec/mongo/operation/limited_spec.rb +3 -3
  173. data/spec/mongo/operation/{commands/map_reduce_spec.rb → map_reduce_spec.rb} +1 -1
  174. data/spec/mongo/operation/read_preference_spec.rb +2 -2
  175. data/spec/mongo/operation/{write/command/remove_user_spec.rb → remove_user_spec.rb} +1 -1
  176. data/spec/mongo/operation/{write/bulk/update_spec.rb → update/bulk_spec.rb} +8 -8
  177. data/spec/mongo/operation/update/command_spec.rb +114 -0
  178. data/spec/mongo/operation/{write/command/update_spec.rb → update/op_msg_spec.rb} +49 -40
  179. data/spec/mongo/operation/{write/update_spec.rb → update_spec.rb} +6 -6
  180. data/spec/mongo/operation/{write/command/update_user_spec.rb → update_user_spec.rb} +1 -1
  181. data/spec/mongo/server/connection_spec.rb +0 -22
  182. data/spec/mongo/server_selector_spec.rb +55 -0
  183. data/spec/mongo/server_spec.rb +0 -42
  184. data/spec/mongo/session/session_pool_spec.rb +1 -1
  185. data/spec/mongo/uri/srv_protocol_spec.rb +2 -2
  186. data/spec/mongo/uri_spec.rb +2 -2
  187. data/spec/support/gridfs_tests/delete.yml +4 -38
  188. data/spec/support/gridfs_tests/download.yml +12 -30
  189. data/spec/support/server_selection.rb +1 -1
  190. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest.yml +0 -1
  191. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_multiple.yml +0 -1
  192. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_non_matching.yml +0 -1
  193. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PossiblePrimary.yml +15 -0
  194. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PossiblePrimaryNearest.yml +15 -0
  195. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Primary.yml +0 -3
  196. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred.yml +0 -1
  197. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred_non_matching.yml +0 -1
  198. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary.yml +0 -1
  199. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred.yml +0 -1
  200. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred_non_matching.yml +0 -1
  201. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_non_matching.yml +0 -1
  202. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest.yml +0 -1
  203. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_multiple.yml +0 -1
  204. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_non_matching.yml +0 -1
  205. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Primary.yml +0 -3
  206. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred.yml +0 -1
  207. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred_non_matching.yml +0 -1
  208. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary.yml +0 -1
  209. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred.yml +0 -1
  210. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred_non_matching.yml +0 -1
  211. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary_non_matching.yml +0 -1
  212. data/spec/support/server_selection/selection/Sharded/read/Nearest.yml +21 -0
  213. data/spec/support/server_selection/selection/Sharded/read/Primary.yml +19 -0
  214. data/spec/support/server_selection/selection/Sharded/read/PrimaryPreferred.yml +21 -0
  215. data/spec/support/server_selection/selection/Sharded/read/Secondary.yml +21 -0
  216. data/spec/support/server_selection/selection/Sharded/read/SecondaryPreferred.yml +0 -5
  217. data/spec/support/server_selection/selection/Single/read/SecondaryPreferred.yml +0 -1
  218. data/spec/support/server_selection/selection/Unknown/read/SecondaryPreferred.yml +0 -1
  219. data/spec/support/shared/session.rb +46 -5
  220. metadata +174 -116
  221. metadata.gz.sig +1 -2
  222. data/lib/mongo/operation/commands.rb +0 -31
  223. data/lib/mongo/operation/commands/aggregate.rb +0 -63
  224. data/lib/mongo/operation/commands/aggregate/result.rb +0 -89
  225. data/lib/mongo/operation/commands/collections_info.rb +0 -71
  226. data/lib/mongo/operation/commands/create.rb +0 -49
  227. data/lib/mongo/operation/commands/drop.rb +0 -49
  228. data/lib/mongo/operation/commands/drop_database.rb +0 -49
  229. data/lib/mongo/operation/commands/explain.rb +0 -27
  230. data/lib/mongo/operation/commands/explain/result.rb +0 -52
  231. data/lib/mongo/operation/commands/find/result.rb +0 -62
  232. data/lib/mongo/operation/commands/get_more.rb +0 -27
  233. data/lib/mongo/operation/commands/get_more/result.rb +0 -62
  234. data/lib/mongo/operation/commands/indexes.rb +0 -73
  235. data/lib/mongo/operation/commands/list_collections.rb +0 -48
  236. data/lib/mongo/operation/commands/list_collections/result.rb +0 -94
  237. data/lib/mongo/operation/commands/list_indexes.rb +0 -48
  238. data/lib/mongo/operation/commands/list_indexes/result.rb +0 -98
  239. data/lib/mongo/operation/commands/map_reduce.rb +0 -65
  240. data/lib/mongo/operation/commands/map_reduce/result.rb +0 -131
  241. data/lib/mongo/operation/commands/parallel_scan.rb +0 -54
  242. data/lib/mongo/operation/commands/parallel_scan/result.rb +0 -64
  243. data/lib/mongo/operation/commands/users_info.rb +0 -52
  244. data/lib/mongo/operation/read.rb +0 -16
  245. data/lib/mongo/operation/read/get_more.rb +0 -52
  246. data/lib/mongo/operation/read/query.rb +0 -55
  247. data/lib/mongo/operation/uses_command_op_msg.rb +0 -78
  248. data/lib/mongo/operation/write.rb +0 -22
  249. data/lib/mongo/operation/write/bulk.rb +0 -20
  250. data/lib/mongo/operation/write/bulk/bulkable.rb +0 -82
  251. data/lib/mongo/operation/write/bulk/delete.rb +0 -71
  252. data/lib/mongo/operation/write/bulk/delete/result.rb +0 -71
  253. data/lib/mongo/operation/write/bulk/insert.rb +0 -96
  254. data/lib/mongo/operation/write/bulk/insert/result.rb +0 -129
  255. data/lib/mongo/operation/write/bulk/legacy_mergable.rb +0 -87
  256. data/lib/mongo/operation/write/bulk/mergable.rb +0 -73
  257. data/lib/mongo/operation/write/bulk/update.rb +0 -81
  258. data/lib/mongo/operation/write/bulk/update/result.rb +0 -196
  259. data/lib/mongo/operation/write/command.rb +0 -23
  260. data/lib/mongo/operation/write/command/create_index.rb +0 -79
  261. data/lib/mongo/operation/write/command/create_user.rb +0 -61
  262. data/lib/mongo/operation/write/command/delete.rb +0 -79
  263. data/lib/mongo/operation/write/command/drop_index.rb +0 -80
  264. data/lib/mongo/operation/write/command/insert.rb +0 -69
  265. data/lib/mongo/operation/write/command/remove_user.rb +0 -60
  266. data/lib/mongo/operation/write/command/update.rb +0 -77
  267. data/lib/mongo/operation/write/command/update_user.rb +0 -61
  268. data/lib/mongo/operation/write/command/writable.rb +0 -70
  269. data/lib/mongo/operation/write/delete.rb +0 -75
  270. data/lib/mongo/operation/write/gle.rb +0 -49
  271. data/lib/mongo/operation/write/idable.rb +0 -63
  272. data/lib/mongo/operation/write/insert.rb +0 -74
  273. data/lib/mongo/operation/write/insert/result.rb +0 -62
  274. data/lib/mongo/operation/write/update.rb +0 -91
  275. data/lib/mongo/operation/write/write_command_enabled.rb +0 -77
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2017 MongoDB, Inc.
1
+ # Copyright (C) 2014-2018 MongoDB, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,26 +14,27 @@
14
14
 
15
15
  module Mongo
16
16
  module Operation
17
- module Commands
18
- class CollectionsInfo
17
+ class UsersInfo
19
18
 
20
- # Defines custom behaviour of results when query the system.namespaces
21
- # collection.
19
+ # Defines custom behaviour of results when using the
20
+ # usersInfo command.
21
+ #
22
+ # @since 2.1.0
23
+ class Result < Operation::Result
24
+
25
+ # The field name for the users document in a usersInfo result.
22
26
  #
23
27
  # @since 2.1.0
24
- class Result < Operation::Result
28
+ USERS = 'users'.freeze
29
+
30
+ def documents
31
+ reply.documents.first[USERS]
32
+ end
33
+
34
+ private
25
35
 
26
- # Get the namespace for the cursor.
27
- #
28
- # @example Get the namespace.
29
- # result.namespace
30
- #
31
- # @return [ String ] The namespace.
32
- #
33
- # @since 2.1.0
34
- def namespace
35
- Database::NAMESPACES
36
- end
36
+ def first_document
37
+ @first_document ||= reply.documents[0]
37
38
  end
38
39
  end
39
40
  end
@@ -122,11 +122,9 @@ module Mongo
122
122
  # @return [ true, false ] If the server is connectable.
123
123
  #
124
124
  # @since 2.1.0
125
- def connectable?
126
- with_connection do |connection|
127
- connection.connectable?
128
- end
129
- end
125
+ #
126
+ # @deprecated No longer necessary with Server Selection specification.
127
+ def connectable?; end
130
128
 
131
129
  # Disconnect the server from the connection.
132
130
  #
@@ -52,9 +52,9 @@ module Mongo
52
52
  # @return [ true, false ] If the connection is connectable.
53
53
  #
54
54
  # @since 2.1.0
55
- def connectable?
56
- begin; ping; rescue; false; end
57
- end
55
+ #
56
+ # @deprecated No longer necessary with Server Selection specification.
57
+ def connectable?; end
58
58
 
59
59
  # Determine if the connection is currently connected.
60
60
  #
@@ -27,31 +27,43 @@ module Mongo
27
27
  # The ping command.
28
28
  #
29
29
  # @since 2.1.0
30
+ #
31
+ # @deprecated No longer necessary with Server Selection specification.
30
32
  PING = { :ping => 1 }.freeze
31
33
 
32
34
  # The ping command for an OP_MSG (server versions >= 3.6).
33
35
  #
34
36
  # @since 2.5.0
37
+ #
38
+ # @deprecated No longer necessary with Server Selection specification.
35
39
  PING_OP_MSG = { :ping => 1, '$db' => Database::ADMIN }.freeze
36
40
 
37
41
  # Ping message.
38
42
  #
39
43
  # @since 2.1.0
44
+ #
45
+ # @deprecated No longer necessary with Server Selection specification.
40
46
  PING_MESSAGE = Protocol::Query.new(Database::ADMIN, Database::COMMAND, PING, :limit => -1)
41
47
 
42
48
  # Ping message as an OP_MSG (server versions >= 3.6).
43
49
  #
44
50
  # @since 2.5.0
51
+ #
52
+ # @deprecated No longer necessary with Server Selection specification.
45
53
  PING_OP_MSG_MESSAGE = Protocol::Msg.new([:none], {}, PING_OP_MSG)
46
54
 
47
55
  # The ping message as raw bytes.
48
56
  #
49
57
  # @since 2.1.0
58
+ #
59
+ # @deprecated No longer necessary with Server Selection specification.
50
60
  PING_BYTES = PING_MESSAGE.serialize.to_s.freeze
51
61
 
52
62
  # The ping OP_MSG message as raw bytes (server versions >= 3.6).
53
63
  #
54
64
  # @since 2.5.0
65
+ #
66
+ # @deprecated No longer necessary with Server Selection specification.
55
67
  PING_OP_MSG_BYTES = PING_OP_MSG_MESSAGE.serialize.to_s.freeze
56
68
 
57
69
  # The last time the connection was checked back into a pool.
@@ -173,6 +185,8 @@ module Mongo
173
185
  # @return [ true, false ] If the server is accepting connections.
174
186
  #
175
187
  # @since 2.1.0
188
+ #
189
+ # @deprecated No longer necessary with Server Selection specification.
176
190
  def ping
177
191
  bytes = features.op_msg_enabled? ? PING_OP_MSG_BYTES : PING_BYTES
178
192
  ensure_connected do |socket|
@@ -71,7 +71,7 @@ module Mongo
71
71
  # @since 2.0.0
72
72
  def get(preference = {})
73
73
  return preference if PREFERENCES.values.include?(preference.class)
74
- PREFERENCES.fetch(preference[:mode] || :primary).new(preference)
74
+ PREFERENCES.fetch((preference[:mode] || :primary).to_sym).new(preference)
75
75
  end
76
76
  end
77
77
  end
@@ -94,7 +94,7 @@ module Mongo
94
94
  # @return [ Mongo::Server ] A server matching the server preference.
95
95
  #
96
96
  # @since 2.0.0
97
- def select_server(cluster, ping = true)
97
+ def select_server(cluster, ping = nil)
98
98
  @local_threshold = cluster.options[:local_threshold] || LOCAL_THRESHOLD
99
99
  @server_selection_timeout = cluster.options[:server_selection_timeout] || SERVER_SELECTION_TIMEOUT
100
100
  deadline = Time.now + server_selection_timeout
@@ -102,17 +102,8 @@ module Mongo
102
102
  servers = candidates(cluster)
103
103
  if servers && !servers.compact.empty?
104
104
  server = servers.first
105
- # There is no point pinging a standalone as the subsequent scan is
106
- # not going to change anything about the cluster.
107
- if ping && !cluster.single?
108
- if server.connectable?
109
- server.check_driver_support!
110
- return server
111
- end
112
- else
113
- server.check_driver_support!
114
- return server
115
- end
105
+ server.check_driver_support!
106
+ return server
116
107
  end
117
108
  cluster.scan!
118
109
  end
@@ -252,7 +252,19 @@ module Mongo
252
252
  #
253
253
  # @since 2.5.1
254
254
  def implicit?
255
- @implicit_session ||= !!(@options.key?(:implicit) && @options[:implicit] == true)
255
+ @implicit ||= !!(@options.key?(:implicit) && @options[:implicit] == true)
256
+ end
257
+
258
+ # Is this session an explicit one (i.e. user-created).
259
+ #
260
+ # @example Is the session explicit?
261
+ # session.explicit?
262
+ #
263
+ # @return [ true, false ] Whether this session is explicit.
264
+ #
265
+ # @since 2.5.2
266
+ def explicit?
267
+ @explicit ||= !implicit?
256
268
  end
257
269
 
258
270
  private
@@ -113,7 +113,7 @@ module Mongo
113
113
  def end_sessions
114
114
  while !@queue.empty?
115
115
  server = ServerSelector.get(mode: :primary_preferred).select_server(@cluster)
116
- Operation::Commands::Command.new(
116
+ Operation::Command.new(
117
117
  :selector => {endSessions: @queue.shift(10_000).collect { |s| s.session_id }},
118
118
  :db_name => Database::ADMIN).execute(server)
119
119
  end
@@ -17,5 +17,5 @@ module Mongo
17
17
  # The current version of the driver.
18
18
  #
19
19
  # @since 2.0.0
20
- VERSION = '2.5.1'.freeze
20
+ VERSION = '2.5.2'.freeze
21
21
  end
@@ -2,6 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe Mongo::Client do
4
4
 
5
+ after do
6
+ begin; client.close; rescue; end
7
+ end
8
+
5
9
  describe '#==' do
6
10
 
7
11
  let(:client) do
@@ -12,12 +16,12 @@ describe Mongo::Client do
12
16
  )
13
17
  end
14
18
 
15
- after do
16
- client.close
17
- end
18
-
19
19
  context 'when the other is a client' do
20
20
 
21
+ after do
22
+ other.close
23
+ end
24
+
21
25
  context 'when the options and cluster are equal' do
22
26
 
23
27
  let(:other) do
@@ -105,6 +109,10 @@ describe Mongo::Client do
105
109
 
106
110
  context 'when the other is a client' do
107
111
 
112
+ after do
113
+ other.close
114
+ end
115
+
108
116
  context 'when the options and cluster are equal' do
109
117
 
110
118
  let(:other) do
@@ -228,10 +236,6 @@ describe Mongo::Client do
228
236
  described_class.new([default_address.seed], authorized_client.options.merge(options))
229
237
  end
230
238
 
231
- after do
232
- client.close
233
- end
234
-
235
239
  it 'sets the option' do
236
240
  expect(client.options['retry_writes']).to eq(options[:retry_writes])
237
241
  end
@@ -243,10 +247,6 @@ describe Mongo::Client do
243
247
  described_class.new([default_address.seed], authorized_client.options.merge(options))
244
248
  end
245
249
 
246
- after do
247
- client.close
248
- end
249
-
250
250
  context 'when the compressor is supported' do
251
251
 
252
252
  let(:options) do
@@ -456,10 +456,6 @@ describe Mongo::Client do
456
456
  authorized_client.with(logger: logger)
457
457
  end
458
458
 
459
- after do
460
- client.close
461
- end
462
-
463
459
  it 'does not use the global logger' do
464
460
  expect(client.cluster.logger).to_not eq(Mongo::Logger.logger)
465
461
  end
@@ -1123,7 +1119,7 @@ describe Mongo::Client do
1123
1119
  end
1124
1120
 
1125
1121
  let(:new_options) do
1126
- { app_name: 'reports' }
1122
+ { app_name: 'client_test' }
1127
1123
  end
1128
1124
 
1129
1125
  let!(:new_client) do
@@ -1373,10 +1369,6 @@ describe Mongo::Client do
1373
1369
  client.list_databases({}, true)
1374
1370
  end
1375
1371
 
1376
- after do
1377
- client.close
1378
- end
1379
-
1380
1372
  it 'sends the command with the nameOnly flag set to true' do
1381
1373
  expect(command[:nameOnly]).to be(true)
1382
1374
  end
@@ -1429,7 +1421,8 @@ describe Mongo::Client do
1429
1421
  end
1430
1422
 
1431
1423
  before do
1432
- expect(client.cluster).to receive(:disconnect!).and_call_original
1424
+ # note that disconnect! is called also in the after block
1425
+ expect(client.cluster).to receive(:disconnect!).twice.and_call_original
1433
1426
  end
1434
1427
 
1435
1428
  it 'disconnects the cluster and returns true' do
@@ -14,18 +14,34 @@ describe Mongo::Cluster::AppMetadata do
14
14
 
15
15
  context 'when the cluster has an app name option set' do
16
16
 
17
+ let(:client) do
18
+ authorized_client.with(app_name: :app_metadata_test)
19
+ end
20
+
17
21
  let(:cluster) do
18
- authorized_client.with(app_name: :reports).cluster
22
+ client.cluster
23
+ end
24
+
25
+ after do
26
+ client.close
19
27
  end
20
28
 
21
29
  it 'sets the app name' do
22
- expect(app_metadata.send(:full_client_document)[:application][:name]).to eq(:reports)
30
+ expect(app_metadata.send(:full_client_document)[:application][:name]).to eq('app_metadata_test')
23
31
  end
24
32
 
25
33
  context 'when the app name exceeds the max length of 128' do
26
34
 
35
+ let(:client) do
36
+ authorized_client.with(app_name: "\u3042"*43)
37
+ end
38
+
27
39
  let(:cluster) do
28
- authorized_client.with(app_name: "\u3042"*43).cluster
40
+ client.cluster
41
+ end
42
+
43
+ after do
44
+ client.close
29
45
  end
30
46
 
31
47
  it 'raises an error' do
@@ -143,4 +143,41 @@ describe Mongo::Cluster::CursorReaper do
143
143
  end
144
144
  end
145
145
  end
146
+
147
+ context 'when a non-exhausted cursor goes out of scope' do
148
+
149
+ let(:docs) do
150
+ 103.times.collect { |i| { a: i } }
151
+ end
152
+
153
+ let(:periodic_executor) do
154
+ cluster.instance_variable_get(:@periodic_executor)
155
+ end
156
+
157
+ let(:cluster) do
158
+ authorized_client.cluster
159
+ end
160
+
161
+ let(:cursor) do
162
+ view = authorized_collection.find
163
+ view.to_enum.next
164
+ cursor = view.instance_variable_get(:@cursor)
165
+ end
166
+
167
+ around do |example|
168
+ authorized_collection.insert_many(docs)
169
+ periodic_executor.stop!
170
+ cluster.schedule_kill_cursor(cursor.id, cursor.send(:kill_cursors_op_spec),
171
+ cursor.instance_variable_get(:@server))
172
+ periodic_executor.flush
173
+ example.run
174
+ periodic_executor.run!
175
+ end
176
+
177
+ it 'schedules the kill cursor op' do
178
+ expect {
179
+ cursor.to_a
180
+ }.to raise_exception(Mongo::Error::OperationFailure)
181
+ end
182
+ end
146
183
  end
@@ -491,11 +491,11 @@ describe Mongo::Cluster do
491
491
  context 'when the client has an app_name set' do
492
492
 
493
493
  let(:cluster) do
494
- authorized_client.with(app_name: 'reports').cluster
494
+ authorized_client.with(app_name: 'cluster_test').cluster
495
495
  end
496
496
 
497
497
  it 'constructs an AppMetadata object with the app_name' do
498
- expect(cluster.app_metadata.send(:full_client_document)[:application]).to eq('name' => 'reports')
498
+ expect(cluster.app_metadata.send(:full_client_document)[:application]).to eq('name' => 'cluster_test')
499
499
  end
500
500
  end
501
501
 
@@ -567,7 +567,7 @@ describe Mongo::Collection::View::ChangeStream, if: test_change_streams? do
567
567
  authorized_collection.insert_one(a: 2)
568
568
  expect(cursor).to receive(:get_more).once.and_raise(error)
569
569
  expect(cursor).to receive(:kill_cursors).and_call_original
570
- expect(Mongo::Operation::Commands::Aggregate).to receive(:new).and_call_original
570
+ expect(Mongo::Operation::Aggregate).to receive(:new).and_call_original
571
571
  end
572
572
 
573
573
  let(:enum) do
@@ -649,7 +649,7 @@ describe Mongo::Collection::View::ChangeStream, if: test_change_streams? do
649
649
  authorized_collection.insert_one(a: 2)
650
650
  expect(cursor).to receive(:get_more).and_raise(Mongo::Error::OperationFailure)
651
651
  expect(cursor).to receive(:kill_cursors).and_call_original
652
- expect(Mongo::Operation::Commands::Aggregate).not_to receive(:new)
652
+ expect(Mongo::Operation::Aggregate).not_to receive(:new)
653
653
  end
654
654
 
655
655
  let(:enum) do
@@ -1113,7 +1113,7 @@ describe Mongo::Collection do
1113
1113
  it_behaves_like 'a failed operation using a session'
1114
1114
  end
1115
1115
 
1116
- context 'when unacknowledged writes is used' do
1116
+ context 'when unacknowledged writes is used with an explicit session' do
1117
1117
 
1118
1118
  let(:collection_with_unacknowledged_write_concern) do
1119
1119
  authorized_collection.with(write: { w: 0 })
@@ -1123,7 +1123,20 @@ describe Mongo::Collection do
1123
1123
  collection_with_unacknowledged_write_concern.insert_many([{ name: 'test1' }, { name: 'test2' }], session: session)
1124
1124
  end
1125
1125
 
1126
- it_behaves_like 'a causally consistent client session with an unacknowledged write'
1126
+ it_behaves_like 'an explicit session with an unacknowledged write'
1127
+ end
1128
+
1129
+ context 'when unacknowledged writes is used with an implicit session' do
1130
+
1131
+ let(:collection_with_unacknowledged_write_concern) do
1132
+ subscribed_client.with(write: { w: 0 })[TEST_COLL]
1133
+ end
1134
+
1135
+ let(:operation) do
1136
+ collection_with_unacknowledged_write_concern.insert_many([{ name: 'test1' }, { name: 'test2' }])
1137
+ end
1138
+
1139
+ it_behaves_like 'an implicit session with an unacknowledged write'
1127
1140
  end
1128
1141
 
1129
1142
  context 'when a document contains invalid keys' do
@@ -1345,7 +1358,7 @@ describe Mongo::Collection do
1345
1358
  it_behaves_like 'a failed operation using a session'
1346
1359
  end
1347
1360
 
1348
- context 'when unacknowledged writes is used' do
1361
+ context 'when unacknowledged writes is used with an explicit session' do
1349
1362
 
1350
1363
  let(:collection_with_unacknowledged_write_concern) do
1351
1364
  authorized_collection.with(write: { w: 0 })
@@ -1355,7 +1368,20 @@ describe Mongo::Collection do
1355
1368
  collection_with_unacknowledged_write_concern.insert_one({ name: 'testing' }, session: session)
1356
1369
  end
1357
1370
 
1358
- it_behaves_like 'a causally consistent client session with an unacknowledged write'
1371
+ it_behaves_like 'an explicit session with an unacknowledged write'
1372
+ end
1373
+
1374
+ context 'when unacknowledged writes is used with an implicit session' do
1375
+
1376
+ let(:collection_with_unacknowledged_write_concern) do
1377
+ subscribed_client.with(write: { w: 0 })[TEST_COLL]
1378
+ end
1379
+
1380
+ let(:operation) do
1381
+ collection_with_unacknowledged_write_concern.insert_one({ name: 'testing' })
1382
+ end
1383
+
1384
+ it_behaves_like 'an implicit session with an unacknowledged write'
1359
1385
  end
1360
1386
 
1361
1387
  context 'when the document contains invalid keys' do
@@ -1993,7 +2019,20 @@ describe Mongo::Collection do
1993
2019
  collection_with_unacknowledged_write_concern.delete_one({}, session: session)
1994
2020
  end
1995
2021
 
1996
- it_behaves_like 'a causally consistent client session with an unacknowledged write'
2022
+ it_behaves_like 'an explicit session with an unacknowledged write'
2023
+ end
2024
+
2025
+ context 'when unacknowledged writes is used with an implicit session' do
2026
+
2027
+ let(:collection_with_unacknowledged_write_concern) do
2028
+ subscribed_client.with(write: { w: 0 })[TEST_COLL]
2029
+ end
2030
+
2031
+ let(:operation) do
2032
+ collection_with_unacknowledged_write_concern.delete_one
2033
+ end
2034
+
2035
+ it_behaves_like 'an implicit session with an unacknowledged write'
1997
2036
  end
1998
2037
 
1999
2038
  context 'when a collation is provided' do
@@ -2155,7 +2194,7 @@ describe Mongo::Collection do
2155
2194
  it_behaves_like 'a failed operation using a session'
2156
2195
  end
2157
2196
 
2158
- context 'when unacknowledged writes is used' do
2197
+ context 'when unacknowledged writes is used with an explicit session' do
2159
2198
 
2160
2199
  let(:collection_with_unacknowledged_write_concern) do
2161
2200
  authorized_collection.with(write: { w: 0 })
@@ -2165,7 +2204,20 @@ describe Mongo::Collection do
2165
2204
  collection_with_unacknowledged_write_concern.delete_many({ '$._id' => 1}, session: session)
2166
2205
  end
2167
2206
 
2168
- it_behaves_like 'a causally consistent client session with an unacknowledged write'
2207
+ it_behaves_like 'an explicit session with an unacknowledged write'
2208
+ end
2209
+
2210
+ context 'when unacknowledged writes is used with an implicit session' do
2211
+
2212
+ let(:collection_with_unacknowledged_write_concern) do
2213
+ subscribed_client.with(write: { w: 0 })[TEST_COLL]
2214
+ end
2215
+
2216
+ let(:operation) do
2217
+ collection_with_unacknowledged_write_concern.delete_many({ '$._id' => 1 })
2218
+ end
2219
+
2220
+ it_behaves_like 'an implicit session with an unacknowledged write'
2169
2221
  end
2170
2222
 
2171
2223
  context 'when a collation is specified' do
@@ -2714,7 +2766,7 @@ describe Mongo::Collection do
2714
2766
  it_behaves_like 'a failed operation using a session'
2715
2767
  end
2716
2768
 
2717
- context 'when unacknowledged writes is used' do
2769
+ context 'when unacknowledged writes is used with an explicit session' do
2718
2770
 
2719
2771
  let(:collection_with_unacknowledged_write_concern) do
2720
2772
  authorized_collection.with(write: { w: 0 })
@@ -2724,7 +2776,20 @@ describe Mongo::Collection do
2724
2776
  collection_with_unacknowledged_write_concern.replace_one({ a: 1 }, { x: 5 }, session: session)
2725
2777
  end
2726
2778
 
2727
- it_behaves_like 'a causally consistent client session with an unacknowledged write'
2779
+ it_behaves_like 'an explicit session with an unacknowledged write'
2780
+ end
2781
+
2782
+ context 'when unacknowledged writes is used with an implicit session' do
2783
+
2784
+ let(:collection_with_unacknowledged_write_concern) do
2785
+ subscribed_client.with(write: { w: 0 })[TEST_COLL]
2786
+ end
2787
+
2788
+ let(:operation) do
2789
+ collection_with_unacknowledged_write_concern.replace_one({ a: 1 }, { x: 5 })
2790
+ end
2791
+
2792
+ it_behaves_like 'an implicit session with an unacknowledged write'
2728
2793
  end
2729
2794
  end
2730
2795
 
@@ -3118,7 +3183,7 @@ describe Mongo::Collection do
3118
3183
  it_behaves_like 'a failed operation using a session'
3119
3184
  end
3120
3185
 
3121
- context 'when unacknowledged writes is used' do
3186
+ context 'when unacknowledged writes is used with an explicit session' do
3122
3187
 
3123
3188
  let(:collection_with_unacknowledged_write_concern) do
3124
3189
  authorized_collection.with(write: { w: 0 })
@@ -3128,7 +3193,20 @@ describe Mongo::Collection do
3128
3193
  collection_with_unacknowledged_write_concern.update_many({a: 1}, { '$set' => {x: 1} }, session: session)
3129
3194
  end
3130
3195
 
3131
- it_behaves_like 'a causally consistent client session with an unacknowledged write'
3196
+ it_behaves_like 'an explicit session with an unacknowledged write'
3197
+ end
3198
+
3199
+ context 'when unacknowledged writes is used with an implicit session' do
3200
+
3201
+ let(:collection_with_unacknowledged_write_concern) do
3202
+ subscribed_client.with(write: { w: 0 })[TEST_COLL]
3203
+ end
3204
+
3205
+ let(:operation) do
3206
+ collection_with_unacknowledged_write_concern.update_many({a: 1}, {'$set' => {x: 1}})
3207
+ end
3208
+
3209
+ it_behaves_like 'an implicit session with an unacknowledged write'
3132
3210
  end
3133
3211
  end
3134
3212
 
@@ -3525,17 +3603,30 @@ describe Mongo::Collection do
3525
3603
  it_behaves_like 'a failed operation using a session'
3526
3604
  end
3527
3605
 
3528
- context 'when unacknowledged writes is used' do
3606
+ context 'when unacknowledged writes is used with an explicit session' do
3529
3607
 
3530
3608
  let(:collection_with_unacknowledged_write_concern) do
3531
3609
  authorized_collection.with(write: { w: 0 })
3532
3610
  end
3533
3611
 
3534
3612
  let(:operation) do
3535
- collection_with_unacknowledged_write_concern.update_one({a: 1}, { '$set' => {x: 1} }, session: session)
3613
+ collection_with_unacknowledged_write_concern.update_one({ a: 1 }, { '$set' => { x: 1 } }, session: session)
3614
+ end
3615
+
3616
+ it_behaves_like 'an explicit session with an unacknowledged write'
3617
+ end
3618
+
3619
+ context 'when unacknowledged writes is used with an implicit session' do
3620
+
3621
+ let(:collection_with_unacknowledged_write_concern) do
3622
+ subscribed_client.with(write: { w: 0 })[TEST_COLL]
3623
+ end
3624
+
3625
+ let(:operation) do
3626
+ collection_with_unacknowledged_write_concern.update_one({ a: 1 }, { '$set' => { x: 1 }})
3536
3627
  end
3537
3628
 
3538
- it_behaves_like 'a causally consistent client session with an unacknowledged write'
3629
+ it_behaves_like 'an implicit session with an unacknowledged write'
3539
3630
  end
3540
3631
  end
3541
3632