mongo 2.5.0.beta → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/mongo/address.rb +1 -1
  5. data/lib/mongo/address/unix.rb +1 -1
  6. data/lib/mongo/auth/user.rb +0 -5
  7. data/lib/mongo/auth/user/view.rb +4 -4
  8. data/lib/mongo/bulk_write.rb +60 -32
  9. data/lib/mongo/client.rb +44 -8
  10. data/lib/mongo/cluster.rb +14 -12
  11. data/lib/mongo/cluster/periodic_executor.rb +106 -0
  12. data/lib/mongo/cluster/{cursor_reaper.rb → reapers/cursor_reaper.rb} +5 -37
  13. data/lib/mongo/cluster/reapers/socket_reaper.rb +59 -0
  14. data/lib/mongo/collection.rb +9 -6
  15. data/lib/mongo/collection/view.rb +2 -2
  16. data/lib/mongo/collection/view/builder/aggregation.rb +2 -1
  17. data/lib/mongo/collection/view/builder/find_command.rb +1 -1
  18. data/lib/mongo/collection/view/change_stream.rb +14 -1
  19. data/lib/mongo/collection/view/map_reduce.rb +30 -13
  20. data/lib/mongo/collection/view/readable.rb +5 -5
  21. data/lib/mongo/collection/view/writable.rb +98 -51
  22. data/lib/mongo/error.rb +3 -0
  23. data/lib/mongo/error/invalid_txt_record.rb +27 -0
  24. data/lib/mongo/error/invalid_uri.rb +7 -6
  25. data/lib/mongo/error/mismatched_domain.rb +27 -0
  26. data/lib/mongo/error/no_srv_records.rb +26 -0
  27. data/lib/mongo/error/unsupported_features.rb +0 -18
  28. data/lib/mongo/index/view.rb +2 -2
  29. data/lib/mongo/operation.rb +1 -0
  30. data/lib/mongo/operation/causally_consistent.rb +33 -0
  31. data/lib/mongo/operation/commands.rb +2 -1
  32. data/lib/mongo/operation/commands/aggregate.rb +2 -7
  33. data/lib/mongo/operation/commands/count.rb +27 -0
  34. data/lib/mongo/operation/commands/distinct.rb +27 -0
  35. data/lib/mongo/operation/commands/find.rb +3 -1
  36. data/lib/mongo/operation/commands/map_reduce.rb +1 -0
  37. data/lib/mongo/operation/commands/parallel_scan.rb +1 -0
  38. data/lib/mongo/operation/specifiable.rb +12 -0
  39. data/lib/mongo/operation/uses_command_op_msg.rb +36 -5
  40. data/lib/mongo/operation/write.rb +0 -5
  41. data/lib/mongo/operation/write/bulk/bulkable.rb +4 -8
  42. data/lib/mongo/operation/write/bulk/mergable.rb +2 -0
  43. data/lib/mongo/operation/write/command/create_index.rb +19 -0
  44. data/lib/mongo/operation/write/command/create_user.rb +19 -0
  45. data/lib/mongo/operation/write/command/delete.rb +1 -2
  46. data/lib/mongo/operation/write/command/drop_index.rb +19 -0
  47. data/lib/mongo/operation/write/command/insert.rb +1 -2
  48. data/lib/mongo/operation/write/command/remove_user.rb +19 -0
  49. data/lib/mongo/operation/write/command/update.rb +1 -2
  50. data/lib/mongo/operation/write/command/update_user.rb +19 -0
  51. data/lib/mongo/operation/write/write_command_enabled.rb +1 -3
  52. data/lib/mongo/protocol/compressed.rb +2 -1
  53. data/lib/mongo/protocol/serializers.rb +6 -6
  54. data/lib/mongo/retryable.rb +48 -5
  55. data/lib/mongo/server.rb +15 -0
  56. data/lib/mongo/server/connection.rb +21 -1
  57. data/lib/mongo/server/connection_pool.rb +3 -0
  58. data/lib/mongo/server/connection_pool/queue.rb +50 -5
  59. data/lib/mongo/server/description.rb +11 -3
  60. data/lib/mongo/server/description/features.rb +26 -7
  61. data/lib/mongo/session.rb +133 -6
  62. data/lib/mongo/session/server_session.rb +30 -0
  63. data/lib/mongo/session/session_pool.rb +20 -20
  64. data/lib/mongo/uri.rb +88 -44
  65. data/lib/mongo/uri/srv_protocol.rb +158 -0
  66. data/lib/mongo/version.rb +1 -1
  67. data/lib/mongo/write_concern/normalizable.rb +12 -0
  68. data/mongo.gemspec +1 -2
  69. data/spec/mongo/address_spec.rb +12 -0
  70. data/spec/mongo/auth/user/view_spec.rb +1 -5
  71. data/spec/mongo/bulk_write_spec.rb +232 -401
  72. data/spec/mongo/change_stream_examples_spec.rb +150 -0
  73. data/spec/mongo/client_spec.rb +142 -2
  74. data/spec/mongo/cluster/cursor_reaper_spec.rb +0 -70
  75. data/spec/mongo/cluster/socket_reaper_spec.rb +32 -0
  76. data/spec/mongo/cluster_spec.rb +11 -7
  77. data/spec/mongo/collection/view/aggregation_spec.rb +46 -1
  78. data/spec/mongo/collection/view/builder/find_command_spec.rb +15 -0
  79. data/spec/mongo/collection/view/change_stream_spec.rb +79 -12
  80. data/spec/mongo/collection/view/map_reduce_spec.rb +120 -4
  81. data/spec/mongo/collection/view/readable_spec.rb +23 -5
  82. data/spec/mongo/collection_spec.rb +292 -102
  83. data/spec/mongo/command_monitoring_spec.rb +26 -32
  84. data/spec/mongo/crud_spec.rb +1 -1
  85. data/spec/mongo/cursor_spec.rb +2 -3
  86. data/spec/mongo/database_spec.rb +30 -14
  87. data/spec/mongo/dns_seedlist_discovery_spec.rb +94 -0
  88. data/spec/mongo/grid/fs_bucket_spec.rb +1 -1
  89. data/spec/mongo/grid/stream/write_spec.rb +1 -1
  90. data/spec/mongo/index/view_spec.rb +8 -46
  91. data/spec/mongo/operation/write/bulk/delete_spec.rb +2 -2
  92. data/spec/mongo/operation/write/bulk/insert_spec.rb +2 -10
  93. data/spec/mongo/operation/write/{create_index_spec.rb → command/create_index_spec.rb} +2 -6
  94. data/spec/mongo/operation/write/command/delete_spec.rb +35 -7
  95. data/spec/mongo/operation/write/{drop_index_spec.rb → command/drop_index_spec.rb} +1 -1
  96. data/spec/mongo/operation/write/command/insert_spec.rb +37 -6
  97. data/spec/mongo/operation/write/{remove_user_spec.rb → command/remove_user_spec.rb} +2 -6
  98. data/spec/mongo/operation/write/command/update_spec.rb +34 -7
  99. data/spec/mongo/operation/write/{update_user_spec.rb → command/update_user_spec.rb} +1 -1
  100. data/spec/mongo/operation/write/create_user_spec.rb +1 -1
  101. data/spec/mongo/operation/write/delete_spec.rb +1 -1
  102. data/spec/mongo/operation/write/insert_spec.rb +2 -10
  103. data/spec/mongo/operation/write/update_spec.rb +3 -15
  104. data/spec/mongo/retryable_spec.rb +1 -1
  105. data/spec/mongo/retryable_writes_spec.rb +815 -0
  106. data/spec/mongo/server/connection_pool/queue_spec.rb +35 -2
  107. data/spec/mongo/server/connection_pool_spec.rb +234 -1
  108. data/spec/mongo/server/connection_spec.rb +10 -6
  109. data/spec/mongo/server/description/features_spec.rb +51 -37
  110. data/spec/mongo/server/description_spec.rb +6 -3
  111. data/spec/mongo/server_spec.rb +87 -0
  112. data/spec/mongo/session/server_session_spec.rb +43 -0
  113. data/spec/mongo/session/session_pool_spec.rb +63 -27
  114. data/spec/mongo/session_spec.rb +247 -0
  115. data/spec/mongo/shell_examples_spec.rb +2 -2
  116. data/spec/mongo/uri/srv_protocol_spec.rb +933 -0
  117. data/spec/mongo/uri_spec.rb +42 -3
  118. data/spec/mongo/write_concern/acknowledged_spec.rb +11 -0
  119. data/spec/mongo/write_concern/unacknowledged_spec.rb +11 -0
  120. data/spec/spec_helper.rb +11 -25
  121. data/spec/support/authorization.rb +2 -1
  122. data/spec/support/connection_string.rb +8 -4
  123. data/spec/support/crud.rb +38 -24
  124. data/spec/support/crud/write.rb +30 -3
  125. data/spec/support/crud_tests/read/aggregate-out.yml +21 -0
  126. data/spec/support/crud_tests/write/bulkWrite-arrayFilters.yml +44 -0
  127. data/spec/support/crud_tests/write/findOneAndUpdate-arrayFilters.yml +1 -1
  128. data/spec/support/crud_tests/write/insertMany.yml +1 -3
  129. data/spec/support/crud_tests/write/replaceOne.yml +1 -1
  130. data/spec/support/crud_tests/write/updateMany-arrayFilters.yml +1 -1
  131. data/spec/support/crud_tests/write/updateOne-arrayFilters.yml +1 -1
  132. data/spec/support/dns_seedlist_discovery_tests/longer-parent-in-return.yml +11 -0
  133. data/spec/support/dns_seedlist_discovery_tests/misformatted-option.yml +5 -0
  134. data/spec/support/dns_seedlist_discovery_tests/no-results.yml +5 -0
  135. data/spec/support/dns_seedlist_discovery_tests/not-enough-parts.yml +5 -0
  136. data/spec/support/dns_seedlist_discovery_tests/one-result-default-port.yml +10 -0
  137. data/spec/support/dns_seedlist_discovery_tests/one-txt-record-multiple-strings.yml +10 -0
  138. data/spec/support/dns_seedlist_discovery_tests/one-txt-record.yml +11 -0
  139. data/spec/support/dns_seedlist_discovery_tests/parent-part-mismatch1.yml +5 -0
  140. data/spec/support/dns_seedlist_discovery_tests/parent-part-mismatch2.yml +5 -0
  141. data/spec/support/dns_seedlist_discovery_tests/parent-part-mismatch3.yml +5 -0
  142. data/spec/support/dns_seedlist_discovery_tests/parent-part-mismatch4.yml +5 -0
  143. data/spec/support/dns_seedlist_discovery_tests/parent-part-mismatch5.yml +5 -0
  144. data/spec/support/dns_seedlist_discovery_tests/returned-parent-too-short.yml +5 -0
  145. data/spec/support/dns_seedlist_discovery_tests/returned-parent-wrong.yml +5 -0
  146. data/spec/support/dns_seedlist_discovery_tests/two-results-default-port.yml +11 -0
  147. data/spec/support/dns_seedlist_discovery_tests/two-results-nonstandard-port.yml +11 -0
  148. data/spec/support/dns_seedlist_discovery_tests/two-txt-records.yml +5 -0
  149. data/spec/support/dns_seedlist_discovery_tests/txt-record-not-allowed-option.yml +5 -0
  150. data/spec/support/dns_seedlist_discovery_tests/txt-record-with-overridden-ssl-option.yml +11 -0
  151. data/spec/support/dns_seedlist_discovery_tests/txt-record-with-overridden-uri-option.yml +11 -0
  152. data/spec/support/dns_seedlist_discovery_tests/txt-record-with-unallowed-option.yml +5 -0
  153. data/spec/support/dns_seedlist_discovery_tests/uri-with-port.yml +5 -0
  154. data/spec/support/dns_seedlist_discovery_tests/uri-with-two-hosts.yml +5 -0
  155. data/spec/support/retryable_writes_tests/bulkWrite.yml +305 -0
  156. data/spec/support/retryable_writes_tests/deleteOne.yml +51 -0
  157. data/spec/support/retryable_writes_tests/findOneAndDelete.yml +52 -0
  158. data/spec/support/retryable_writes_tests/findOneAndReplace.yml +57 -0
  159. data/spec/support/retryable_writes_tests/findOneAndUpdate.yml +56 -0
  160. data/spec/support/retryable_writes_tests/insertMany.yml +72 -0
  161. data/spec/support/retryable_writes_tests/insertOne.yml +55 -0
  162. data/spec/support/retryable_writes_tests/replaceOne.yml +60 -0
  163. data/spec/support/retryable_writes_tests/updateOne.yml +120 -0
  164. data/spec/support/shared/session.rb +525 -24
  165. metadata +437 -350
  166. metadata.gz.sig +0 -0
  167. data/lib/mongo/operation/commands/user_query.rb +0 -72
  168. data/lib/mongo/operation/write/create_index.rb +0 -67
  169. data/lib/mongo/operation/write/create_user.rb +0 -50
  170. data/lib/mongo/operation/write/drop_index.rb +0 -63
  171. data/lib/mongo/operation/write/remove_user.rb +0 -48
  172. data/lib/mongo/operation/write/update_user.rb +0 -50
metadata.gz.sig CHANGED
Binary file
@@ -1,72 +0,0 @@
1
- # Copyright (C) 2014-2017 MongoDB, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- module Mongo
16
- module Operation
17
- module Commands
18
-
19
- # A MongoDB operation to get info of a particular user in a database.
20
- #
21
- # @example Create the user query operation.
22
- # UserQuery.new(:name => 'emily', :db_name => 'test-db')
23
- #
24
- # Initialization:
25
- # param [ Hash ] spec The specifications for the user query operation.
26
- #
27
- # option spec :user_name [ String ] The name of the user.
28
- # option spec :db_name [ String ] The name of the database where the user exists.
29
- # option spec :options [ Hash ] Options for the operation.
30
- #
31
- # @since 2.1.0
32
- class UserQuery
33
- include Executable
34
- include Specifiable
35
-
36
- # Execute the operation.
37
- #
38
- # @example Execute the operation.
39
- # operation.execute(server)
40
- #
41
- # @param [ Mongo::Server ] server The server to send this operation to.
42
- #
43
- # @return [ Result ] The operation response, if there is one.
44
- #
45
- # @since 2.1.0
46
- def execute(server)
47
- if server.features.users_info_enabled?
48
- UsersInfo.new(spec).execute(server).validate!
49
- else
50
- server.with_connection do |connection|
51
- Result.new(connection.dispatch([ message(server) ])).validate!
52
- end
53
- end
54
- end
55
-
56
- private
57
-
58
- def selector
59
- { :user => user_name }
60
- end
61
-
62
- def query_coll
63
- Auth::User::COLLECTION
64
- end
65
-
66
- def message(server)
67
- Protocol::Query.new(db_name, query_coll, selector, options)
68
- end
69
- end
70
- end
71
- end
72
- end
@@ -1,67 +0,0 @@
1
-
2
- # Copyright (C) 2014-2017 MongoDB, Inc.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
- module Mongo
17
- module Operation
18
- module Write
19
-
20
- # A MongoDB create index operation.
21
- #
22
- # @note If a server with version >= 2.5.5 is being used, a write command
23
- # operation will be created and sent instead.
24
- #
25
- # @example Create the create index operation.
26
- # Write::CreateIndex.new({
27
- # :index => { :name => 1, :age => -1 },
28
- # :db_name => 'test',
29
- # :coll_name => 'test_coll',
30
- # :index_name => 'name_1_age_-1'
31
- # })
32
- #
33
- # Initialization:
34
- # param [ Hash ] spec The specifications for the insert.
35
- #
36
- # option spec :index [ Hash ] The index spec to create.
37
- # option spec :db_name [ String ] The name of the database.
38
- # option spec :coll_name [ String ] The name of the collection.
39
- # option spec :index_name [ String ] The name of the index.
40
- # option spec :options [ Hash ] Options for the command, if it ends up being a
41
- # write command.
42
- #
43
- # @since 2.0.0
44
- class CreateIndex
45
- include GLE
46
- include WriteCommandEnabled
47
- include Specifiable
48
-
49
- private
50
-
51
- def write_command_op
52
- Command::CreateIndex.new(spec)
53
- end
54
-
55
- def index_documents
56
- indexes.dup.each do |index|
57
- index[:ns] = namespace
58
- end
59
- end
60
-
61
- def message(server)
62
- Protocol::Insert.new(db_name, Index::COLLECTION, index_documents, validating_keys: false)
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,50 +0,0 @@
1
-
2
- # Copyright (C) 2014-2017 MongoDB, Inc.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
- module Mongo
17
- module Operation
18
- module Write
19
-
20
- # A MongoDB create user operation.
21
- #
22
- # @example Initialize the operation.
23
- # Write::CreateUser.new(:db_name => 'test', :user => user)
24
- #
25
- # Initialization:
26
- # param [ Hash ] spec The specifications for the create.
27
- #
28
- # option spec :user [ Auth::User ] The user to create.
29
- # option spec :db_name [ String ] The name of the database.
30
- #
31
- # @since 2.0.0
32
- class CreateUser
33
- include GLE
34
- include WriteCommandEnabled
35
- include Specifiable
36
-
37
- private
38
-
39
- def write_command_op
40
- Command::CreateUser.new(spec)
41
- end
42
-
43
- def message(server)
44
- user_spec = { user: user.name }.merge(user.spec)
45
- Protocol::Insert.new(db_name, Auth::User::COLLECTION, [ user_spec ])
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,63 +0,0 @@
1
- # Copyright (C) 2014-2017 MongoDB, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- module Mongo
16
- module Operation
17
- module Write
18
-
19
- # A MongoDB drop index operation.
20
- #
21
- # @example Create the drop index operation.
22
- # Write::DropIndex.new({
23
- # :db_name => 'test',
24
- # :coll_name => 'test_coll',
25
- # :index_name => 'name_1_age_-1'
26
- # })
27
- #
28
- # Initialization:
29
- # param [ Hash ] spec The specifications for the drop.
30
- #
31
- # option spec :index [ Hash ] The index spec to create.
32
- # option spec :db_name [ String ] The name of the database.
33
- # option spec :coll_name [ String ] The name of the collection.
34
- # option spec :index_name [ String ] The name of the index.
35
- #
36
- # @since 2.0.0
37
- class DropIndex
38
- include WriteCommandEnabled
39
- include Specifiable
40
-
41
- # Execute the drop index operation.
42
- #
43
- # @example Execute the operation.
44
- # operation.execute(server)
45
- #
46
- # @param [ Mongo::Server ] server The server to send this operation to.
47
- #
48
- # @return [ Result ] The result of the operation.
49
- #
50
- # @since 2.0.0
51
- def execute(server)
52
- execute_write_command(server)
53
- end
54
-
55
- private
56
-
57
- def write_command_op
58
- Command::DropIndex.new(spec)
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,48 +0,0 @@
1
- # Copyright (C) 2014-2017 MongoDB, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- module Mongo
16
- module Operation
17
- module Write
18
-
19
- # A MongoDB remove user operation.
20
- #
21
- # @example Create the remove user operation.
22
- # Write::RemoveUser.new(:db_name => 'test', :name => name)
23
- #
24
- # Initialization:
25
- # param [ Hash ] spec The specifications for the remove.
26
- #
27
- # option spec :name [ String ] The user name.
28
- # option spec :db_name [ String ] The name of the database.
29
- #
30
- # @since 2.0.0
31
- class RemoveUser
32
- include GLE
33
- include WriteCommandEnabled
34
- include Specifiable
35
-
36
- private
37
-
38
- def write_command_op
39
- Command::RemoveUser.new(spec)
40
- end
41
-
42
- def message(server)
43
- Protocol::Delete.new(db_name, Auth::User::COLLECTION, { user: user_name })
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,50 +0,0 @@
1
-
2
- # Copyright (C) 2014-2017 MongoDB, Inc.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
- module Mongo
17
- module Operation
18
- module Write
19
-
20
- # A MongoDB update user operation.
21
- #
22
- # @example Initialize the operation.
23
- # Write::UpdateUser.new(:db_name => 'test', :user => user)
24
- #
25
- # Initialization:
26
- # param [ Hash ] spec The specifications for the update.
27
- #
28
- # option spec :user [ Auth::User ] The user to update.
29
- # option spec :db_name [ String ] The name of the database.
30
- #
31
- # @since 2.0.0
32
- class UpdateUser
33
- include GLE
34
- include WriteCommandEnabled
35
- include Specifiable
36
-
37
- private
38
-
39
- def write_command_op
40
- Command::UpdateUser.new(spec)
41
- end
42
-
43
- def message(server)
44
- user_spec = { user: user.name }.merge(user.spec)
45
- Protocol::Update.new(db_name, Auth::User::COLLECTION, { user: user.name }, user_spec)
46
- end
47
- end
48
- end
49
- end
50
- end