mongo 2.4.3 → 2.5.0.beta
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +3 -2
- data.tar.gz.sig +0 -0
- data/lib/mongo.rb +3 -2
- data/lib/mongo/auth/cr.rb +6 -4
- data/lib/mongo/auth/cr/conversation.rb +33 -17
- data/lib/mongo/auth/ldap.rb +4 -2
- data/lib/mongo/auth/ldap/conversation.rb +19 -9
- data/lib/mongo/auth/scram.rb +7 -4
- data/lib/mongo/auth/scram/conversation.rb +62 -24
- data/lib/mongo/auth/user.rb +10 -0
- data/lib/mongo/auth/user/view.rb +44 -22
- data/lib/mongo/auth/x509.rb +4 -2
- data/lib/mongo/auth/x509/conversation.rb +19 -9
- data/lib/mongo/bulk_write.rb +33 -27
- data/lib/mongo/bulk_write/combineable.rb +5 -0
- data/lib/mongo/bulk_write/transformable.rb +2 -0
- data/lib/mongo/bulk_write/validatable.rb +4 -0
- data/lib/mongo/client.rb +123 -12
- data/lib/mongo/cluster.rb +52 -11
- data/lib/mongo/cluster/app_metadata.rb +8 -2
- data/lib/mongo/cluster/cursor_reaper.rb +0 -1
- data/lib/mongo/cluster/topology.rb +1 -1
- data/lib/mongo/collection.rb +114 -27
- data/lib/mongo/collection/view.rb +8 -2
- data/lib/mongo/collection/view/aggregation.rb +11 -7
- data/lib/mongo/collection/view/builder/aggregation.rb +5 -1
- data/lib/mongo/collection/view/builder/find_command.rb +5 -3
- data/lib/mongo/collection/view/builder/map_reduce.rb +11 -3
- data/lib/mongo/collection/view/builder/op_query.rb +1 -1
- data/lib/mongo/collection/view/change_stream.rb +160 -0
- data/lib/mongo/collection/view/change_stream/retryable.rb +57 -0
- data/lib/mongo/collection/view/iterable.rb +11 -10
- data/lib/mongo/collection/view/map_reduce.rb +22 -18
- data/lib/mongo/collection/view/readable.rb +51 -37
- data/lib/mongo/collection/view/writable.rb +72 -40
- data/lib/mongo/cursor.rb +25 -4
- data/lib/mongo/cursor/builder/get_more_command.rb +4 -2
- data/lib/mongo/database.rb +22 -11
- data/lib/mongo/database/view.rb +16 -12
- data/lib/mongo/error.rb +5 -0
- data/lib/mongo/error/invalid_session.rb +36 -0
- data/lib/mongo/error/missing_resume_token.rb +39 -0
- data/lib/mongo/error/operation_failure.rb +17 -0
- data/lib/mongo/error/parser.rb +3 -2
- data/lib/mongo/error/unknown_payload_type.rb +41 -0
- data/lib/mongo/error/unsupported_array_filters.rb +51 -0
- data/lib/mongo/error/unsupported_message_type.rb +23 -0
- data/lib/mongo/grid/fs_bucket.rb +5 -4
- data/lib/mongo/grid/stream/read.rb +3 -2
- data/lib/mongo/grid/stream/write.rb +2 -2
- data/lib/mongo/index/view.rb +35 -25
- data/lib/mongo/monitoring/event/secure.rb +14 -0
- data/lib/mongo/operation.rb +16 -0
- data/lib/mongo/operation/commands.rb +1 -0
- data/lib/mongo/operation/commands/aggregate.rb +9 -5
- data/lib/mongo/operation/commands/aggregate/result.rb +1 -1
- data/lib/mongo/operation/commands/collections_info.rb +6 -6
- data/lib/mongo/operation/commands/command.rb +2 -1
- data/lib/mongo/operation/commands/create.rb +6 -2
- data/lib/mongo/operation/commands/drop.rb +6 -2
- data/lib/mongo/operation/commands/drop_database.rb +6 -2
- data/lib/mongo/operation/commands/explain.rb +27 -0
- data/lib/mongo/operation/commands/explain/result.rb +52 -0
- data/lib/mongo/operation/commands/indexes.rb +1 -1
- data/lib/mongo/operation/commands/list_collections.rb +1 -1
- data/lib/mongo/operation/commands/list_collections/result.rb +1 -1
- data/lib/mongo/operation/commands/list_indexes.rb +1 -1
- data/lib/mongo/operation/commands/list_indexes/result.rb +1 -1
- data/lib/mongo/operation/commands/map_reduce.rb +8 -4
- data/lib/mongo/operation/commands/map_reduce/result.rb +13 -1
- data/lib/mongo/operation/commands/user_query.rb +1 -1
- data/lib/mongo/operation/commands/users_info.rb +6 -2
- data/lib/mongo/operation/executable.rb +4 -1
- data/lib/mongo/operation/read_preference.rb +10 -5
- data/lib/mongo/operation/result.rb +26 -2
- data/lib/mongo/operation/specifiable.rb +13 -1
- data/lib/mongo/operation/uses_command_op_msg.rb +47 -0
- data/lib/mongo/operation/write/bulk/bulkable.rb +4 -1
- data/lib/mongo/operation/write/bulk/insert/result.rb +4 -4
- data/lib/mongo/operation/write/command/create_index.rb +6 -1
- data/lib/mongo/operation/write/command/delete.rb +28 -4
- data/lib/mongo/operation/write/command/drop_index.rb +6 -1
- data/lib/mongo/operation/write/command/insert.rb +22 -18
- data/lib/mongo/operation/write/command/update.rb +24 -9
- data/lib/mongo/operation/write/command/writable.rb +14 -1
- data/lib/mongo/operation/write/insert.rb +4 -1
- data/lib/mongo/operation/write/insert/result.rb +2 -2
- data/lib/mongo/operation/write/update.rb +7 -1
- data/lib/mongo/operation/write/write_command_enabled.rb +20 -3
- data/lib/mongo/protocol.rb +3 -0
- data/lib/mongo/protocol/bit_vector.rb +2 -2
- data/lib/mongo/protocol/compressed.rb +135 -0
- data/lib/mongo/protocol/delete.rb +8 -6
- data/lib/mongo/protocol/get_more.rb +8 -6
- data/lib/mongo/protocol/insert.rb +8 -6
- data/lib/mongo/protocol/kill_cursors.rb +8 -6
- data/lib/mongo/protocol/message.rb +31 -3
- data/lib/mongo/protocol/msg.rb +172 -0
- data/lib/mongo/protocol/query.rb +26 -6
- data/lib/mongo/protocol/registry.rb +76 -0
- data/lib/mongo/protocol/reply.rb +10 -5
- data/lib/mongo/protocol/serializers.rb +224 -0
- data/lib/mongo/protocol/update.rb +8 -6
- data/lib/mongo/retryable.rb +4 -2
- data/lib/mongo/server.rb +6 -3
- data/lib/mongo/server/connectable.rb +1 -1
- data/lib/mongo/server/connection.rb +30 -8
- data/lib/mongo/server/description.rb +25 -1
- data/lib/mongo/server/description/features.rb +4 -1
- data/lib/mongo/server/monitor.rb +5 -0
- data/lib/mongo/server/monitor/connection.rb +50 -2
- data/lib/mongo/server_selector/nearest.rb +10 -4
- data/lib/mongo/server_selector/primary.rb +20 -0
- data/lib/mongo/server_selector/primary_preferred.rb +10 -4
- data/lib/mongo/server_selector/secondary.rb +10 -4
- data/lib/mongo/server_selector/secondary_preferred.rb +24 -4
- data/lib/mongo/session.rb +180 -0
- data/lib/mongo/session/server_session.rb +73 -0
- data/lib/mongo/session/session_pool.rb +161 -0
- data/lib/mongo/uri.rb +11 -0
- data/lib/mongo/version.rb +1 -1
- data/mongo.gemspec +2 -1
- data/spec/mongo/auth/cr_spec.rb +12 -0
- data/spec/mongo/auth/ldap_spec.rb +2 -0
- data/spec/mongo/auth/scram/conversation_spec.rb +6 -6
- data/spec/mongo/auth/scram_spec.rb +25 -1
- data/spec/mongo/auth/user/view_spec.rb +268 -76
- data/spec/mongo/auth/x509_spec.rb +2 -0
- data/spec/mongo/bulk_write_spec.rb +435 -5
- data/spec/mongo/client_spec.rb +356 -39
- data/spec/mongo/cluster/app_metadata_spec.rb +2 -2
- data/spec/mongo/cluster_spec.rb +176 -0
- data/spec/mongo/collection/view/aggregation_spec.rb +33 -12
- data/spec/mongo/collection/view/builder/find_command_spec.rb +46 -6
- data/spec/mongo/collection/view/change_stream_spec.rb +814 -0
- data/spec/mongo/collection/view/map_reduce_spec.rb +94 -17
- data/spec/mongo/collection/view/readable_spec.rb +3 -12
- data/spec/mongo/collection_spec.rb +1048 -42
- data/spec/mongo/cursor/builder/get_more_command_spec.rb +19 -0
- data/spec/mongo/cursor_spec.rb +2 -2
- data/spec/mongo/database_spec.rb +50 -1
- data/spec/mongo/grid/fs_bucket_spec.rb +225 -137
- data/spec/mongo/grid/stream/read_spec.rb +2 -2
- data/spec/mongo/index/view_spec.rb +146 -8
- data/spec/mongo/monitoring/event/secure_spec.rb +42 -0
- data/spec/mongo/operation/read/query_spec.rb +2 -1
- data/spec/mongo/operation/specifiable_spec.rb +2 -2
- data/spec/mongo/operation/write/command/delete_spec.rb +96 -13
- data/spec/mongo/operation/write/command/insert_spec.rb +111 -12
- data/spec/mongo/operation/write/command/update_spec.rb +93 -10
- data/spec/mongo/operation/write/delete_spec.rb +1 -1
- data/spec/mongo/operation/write/insert_spec.rb +1 -1
- data/spec/mongo/operation/write/update_spec.rb +1 -1
- data/spec/mongo/protocol/compressed_spec.rb +66 -0
- data/spec/mongo/protocol/delete_spec.rb +14 -0
- data/spec/mongo/protocol/get_more_spec.rb +14 -0
- data/spec/mongo/protocol/insert_spec.rb +14 -0
- data/spec/mongo/protocol/kill_cursors_spec.rb +14 -0
- data/spec/mongo/protocol/msg_spec.rb +499 -0
- data/spec/mongo/protocol/query_spec.rb +45 -0
- data/spec/mongo/protocol/registry_spec.rb +31 -0
- data/spec/mongo/protocol/reply_spec.rb +14 -0
- data/spec/mongo/protocol/update_spec.rb +14 -0
- data/spec/mongo/retryable_spec.rb +6 -2
- data/spec/mongo/sdam_spec.rb +4 -0
- data/spec/mongo/server/connection_spec.rb +4 -2
- data/spec/mongo/server/description_spec.rb +28 -1
- data/spec/mongo/session/server_session_spec.rb +16 -0
- data/spec/mongo/session/session_pool_spec.rb +194 -0
- data/spec/mongo/uri_spec.rb +31 -2
- data/spec/spec_helper.rb +104 -0
- data/spec/support/authorization.rb +6 -1
- data/spec/support/crud.rb +3 -1
- data/spec/support/crud/write.rb +6 -1
- data/spec/support/crud_tests/write/findOneAndUpdate-arrayFilters.yml +69 -0
- data/spec/support/crud_tests/write/updateMany-arrayFilters.yml +63 -0
- data/spec/support/crud_tests/write/updateOne-arrayFilters.yml +109 -0
- data/spec/support/sdam/rs/discover_arbiters.yml +1 -1
- data/spec/support/sdam/rs/discover_passives.yml +2 -2
- data/spec/support/sdam/rs/discover_primary.yml +1 -1
- data/spec/support/sdam/rs/discover_secondary.yml +1 -1
- data/spec/support/sdam/rs/discovery.yml +4 -4
- data/spec/support/sdam/rs/equal_electionids.yml +1 -0
- data/spec/support/sdam/rs/ghost_discovered.yml +1 -1
- data/spec/support/sdam/rs/hosts_differ_from_seeds.yml +1 -1
- data/spec/support/sdam/rs/ls_timeout.yml +88 -0
- data/spec/support/sdam/rs/member_reconfig.yml +2 -2
- data/spec/support/sdam/rs/member_standalone.yml +2 -2
- data/spec/support/sdam/rs/new_primary.yml +2 -2
- data/spec/support/sdam/rs/new_primary_new_electionid.yml +3 -0
- data/spec/support/sdam/rs/new_primary_new_setversion.yml +3 -0
- data/spec/support/sdam/rs/new_primary_wrong_set_name.yml +2 -2
- data/spec/support/sdam/rs/non_rs_member.yml +1 -1
- data/spec/support/sdam/rs/normalize_case.yml +1 -1
- data/spec/support/sdam/rs/null_election_id.yml +4 -0
- data/spec/support/sdam/rs/primary_becomes_standalone.yml +2 -2
- data/spec/support/sdam/rs/primary_changes_set_name.yml +2 -2
- data/spec/support/sdam/rs/primary_disconnect.yml +2 -2
- data/spec/support/sdam/rs/primary_disconnect_electionid.yml +5 -0
- data/spec/support/sdam/rs/primary_disconnect_setversion.yml +5 -0
- data/spec/support/sdam/rs/primary_hint_from_secondary_with_mismatched_me.yml +58 -0
- data/spec/support/sdam/rs/primary_reports_new_member.yml +4 -4
- data/spec/support/sdam/rs/primary_to_no_primary_mismatched_me.yml +2 -2
- data/spec/support/sdam/rs/primary_wrong_set_name.yml +1 -1
- data/spec/support/sdam/rs/response_from_removed.yml +2 -2
- data/spec/support/sdam/rs/rsother_discovered.yml +1 -1
- data/spec/support/sdam/rs/sec_not_auth.yml +1 -1
- data/spec/support/sdam/rs/secondary_wrong_set_name.yml +1 -1
- data/spec/support/sdam/rs/secondary_wrong_set_name_with_primary.yml +2 -2
- data/spec/support/sdam/rs/setversion_without_electionid.yml +2 -0
- data/spec/support/sdam/rs/stepdown_change_set_name.yml +2 -2
- data/spec/support/sdam/rs/unexpected_mongos.yml +1 -1
- data/spec/support/sdam/rs/use_setversion_without_electionid.yml +3 -0
- data/spec/support/sdam/rs/wrong_set_name.yml +1 -1
- data/spec/support/sdam/sharded/ls_timeout_mongos.yml +97 -0
- data/spec/support/sdam/sharded/mongos_disconnect.yml +3 -3
- data/spec/support/sdam/sharded/multiple_mongoses.yml +1 -1
- data/spec/support/sdam/sharded/non_mongos_removed.yml +1 -1
- data/spec/support/sdam/sharded/normalize_uri_case.yml +1 -1
- data/spec/support/sdam/single/direct_connection_external_ip.yml +1 -1
- data/spec/support/sdam/single/direct_connection_mongos.yml +1 -1
- data/spec/support/sdam/single/direct_connection_rsarbiter.yml +1 -1
- data/spec/support/sdam/single/direct_connection_rsprimary.yml +1 -1
- data/spec/support/sdam/single/direct_connection_rssecondary.yml +1 -1
- data/spec/support/sdam/single/direct_connection_slave.yml +1 -1
- data/spec/support/sdam/single/direct_connection_standalone.yml +1 -1
- data/spec/support/sdam/single/ls_timeout_standalone.yml +35 -0
- data/spec/support/sdam/single/not_ok_response.yml +1 -1
- data/spec/support/sdam/single/standalone_removed.yml +1 -1
- data/spec/support/sdam/single/unavailable_seed.yml +1 -1
- data/spec/support/server_discovery_and_monitoring.rb +4 -0
- data/spec/support/shared/session.rb +236 -0
- metadata +53 -15
- metadata.gz.sig +0 -0
@@ -34,10 +34,12 @@ module Mongo
|
|
34
34
|
# GetMoreCommand.new(cursor)
|
35
35
|
#
|
36
36
|
# @param [ Cursor ] cursor The cursor.
|
37
|
+
# @param [ Session ] session The session.
|
37
38
|
#
|
38
39
|
# @since 2.2.0
|
39
|
-
def initialize(cursor)
|
40
|
+
def initialize(cursor, session = nil)
|
40
41
|
@cursor = cursor
|
42
|
+
@session = session
|
41
43
|
end
|
42
44
|
|
43
45
|
# Get the specification.
|
@@ -49,7 +51,7 @@ module Mongo
|
|
49
51
|
#
|
50
52
|
# @since 2.2.0
|
51
53
|
def specification
|
52
|
-
{ selector: get_more_command, db_name: database.name }
|
54
|
+
{ selector: get_more_command, db_name: database.name, session: @session }
|
53
55
|
end
|
54
56
|
|
55
57
|
private
|
data/lib/mongo/database.rb
CHANGED
@@ -66,6 +66,7 @@ module Mongo
|
|
66
66
|
def_delegators :@client,
|
67
67
|
:cluster,
|
68
68
|
:read_preference,
|
69
|
+
:server_selector,
|
69
70
|
:write_concern
|
70
71
|
|
71
72
|
# @return [ Mongo::Server ] Get the primary server from the cluster.
|
@@ -154,11 +155,14 @@ module Mongo
|
|
154
155
|
def command(operation, opts = {})
|
155
156
|
preference = ServerSelector.get(opts[:read] || ServerSelector::PRIMARY)
|
156
157
|
server = preference.select_server(cluster)
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
158
|
+
client.send(:with_session, opts) do |session|
|
159
|
+
Operation::Commands::Command.new({
|
160
|
+
:selector => operation.dup,
|
161
|
+
:db_name => name,
|
162
|
+
:read => preference,
|
163
|
+
:session => session
|
164
|
+
}).execute(server)
|
165
|
+
end
|
162
166
|
end
|
163
167
|
|
164
168
|
# Drop the database and all its associated information.
|
@@ -166,16 +170,23 @@ module Mongo
|
|
166
170
|
# @example Drop the database.
|
167
171
|
# database.drop
|
168
172
|
#
|
173
|
+
# @param [ Hash ] options The options for the operation.
|
174
|
+
#
|
175
|
+
# @option options [ Session ] :session The session to use for the operation.
|
176
|
+
#
|
169
177
|
# @return [ Result ] The result of the command.
|
170
178
|
#
|
171
179
|
# @since 2.0.0
|
172
|
-
def drop
|
180
|
+
def drop(options = {})
|
173
181
|
operation = { :dropDatabase => 1 }
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
182
|
+
client.send(:with_session, options) do |session|
|
183
|
+
Operation::Commands::DropDatabase.new({
|
184
|
+
selector: operation,
|
185
|
+
db_name: name,
|
186
|
+
write_concern: write_concern,
|
187
|
+
session: session
|
188
|
+
}).execute(next_primary)
|
189
|
+
end
|
179
190
|
end
|
180
191
|
|
181
192
|
# Instantiate a new database object.
|
data/lib/mongo/database/view.rb
CHANGED
@@ -22,7 +22,7 @@ module Mongo
|
|
22
22
|
extend Forwardable
|
23
23
|
include Enumerable
|
24
24
|
|
25
|
-
def_delegators :@database, :cluster, :read_preference
|
25
|
+
def_delegators :@database, :cluster, :read_preference, :client
|
26
26
|
def_delegators :cluster, :next_primary
|
27
27
|
|
28
28
|
# @return [ Integer ] batch_size The size of the batch of results
|
@@ -52,7 +52,8 @@ module Mongo
|
|
52
52
|
@batch_size = options[:batch_size]
|
53
53
|
server = next_primary(false)
|
54
54
|
@limit = -1 if server.features.list_collections_enabled?
|
55
|
-
|
55
|
+
session = client.send(:get_session, options)
|
56
|
+
collections_info(server, session).collect do |info|
|
56
57
|
if server.features.list_collections_enabled?
|
57
58
|
info[Database::NAME]
|
58
59
|
else
|
@@ -71,7 +72,8 @@ module Mongo
|
|
71
72
|
#
|
72
73
|
# @since 2.0.5
|
73
74
|
def list_collections
|
74
|
-
|
75
|
+
session = client.send(:get_session)
|
76
|
+
collections_info(next_primary(false), session)
|
75
77
|
end
|
76
78
|
|
77
79
|
# Create the new database view.
|
@@ -91,27 +93,29 @@ module Mongo
|
|
91
93
|
|
92
94
|
private
|
93
95
|
|
94
|
-
def collections_info(server, &block)
|
95
|
-
cursor = Cursor.new(self, send_initial_query(server), server)
|
96
|
+
def collections_info(server, session, &block)
|
97
|
+
cursor = Cursor.new(self, send_initial_query(server, session), server, session: session)
|
96
98
|
cursor.each do |doc|
|
97
99
|
yield doc
|
98
100
|
end if block_given?
|
99
|
-
cursor
|
101
|
+
cursor.to_enum
|
100
102
|
end
|
101
103
|
|
102
|
-
def collections_info_spec
|
104
|
+
def collections_info_spec(session)
|
103
105
|
{ selector: {
|
104
106
|
listCollections: 1,
|
105
107
|
cursor: batch_size ? { batchSize: batch_size } : {} },
|
106
|
-
db_name: @database.name
|
108
|
+
db_name: @database.name,
|
109
|
+
session: session
|
110
|
+
}
|
107
111
|
end
|
108
112
|
|
109
|
-
def initial_query_op
|
110
|
-
Operation::Commands::CollectionsInfo.new(collections_info_spec)
|
113
|
+
def initial_query_op(session)
|
114
|
+
Operation::Commands::CollectionsInfo.new(collections_info_spec(session))
|
111
115
|
end
|
112
116
|
|
113
|
-
def send_initial_query(server)
|
114
|
-
initial_query_op.execute(server)
|
117
|
+
def send_initial_query(server, session)
|
118
|
+
initial_query_op(session).execute(server)
|
115
119
|
end
|
116
120
|
end
|
117
121
|
end
|
data/lib/mongo/error.rb
CHANGED
@@ -88,6 +88,7 @@ require 'mongo/error/invalid_application_name'
|
|
88
88
|
require 'mongo/error/invalid_nonce'
|
89
89
|
require 'mongo/error/invalid_replacement_document'
|
90
90
|
require 'mongo/error/invalid_server_preference'
|
91
|
+
require 'mongo/error/invalid_session'
|
91
92
|
require 'mongo/error/invalid_signature'
|
92
93
|
require 'mongo/error/invalid_update_document'
|
93
94
|
require 'mongo/error/invalid_uri'
|
@@ -103,5 +104,9 @@ require 'mongo/error/unchangeable_collection_option'
|
|
103
104
|
require 'mongo/error/unexpected_chunk_length'
|
104
105
|
require 'mongo/error/unexpected_response'
|
105
106
|
require 'mongo/error/missing_file_chunk'
|
107
|
+
require 'mongo/error/missing_resume_token'
|
108
|
+
require 'mongo/error/unsupported_array_filters'
|
109
|
+
require 'mongo/error/unknown_payload_type'
|
106
110
|
require 'mongo/error/unsupported_collation'
|
107
111
|
require 'mongo/error/unsupported_features'
|
112
|
+
require 'mongo/error/unsupported_message_type'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Copyright (C) 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
|
+
class Error
|
17
|
+
|
18
|
+
# This exception is raised when a session is attempted to be used and it is invalid.
|
19
|
+
#
|
20
|
+
# @since 2.5.0
|
21
|
+
class InvalidSession < Error
|
22
|
+
|
23
|
+
# Create the new exception.
|
24
|
+
#
|
25
|
+
# @example Create the new exception.
|
26
|
+
# InvalidSession.new(message)
|
27
|
+
#
|
28
|
+
# @param [ String ] message The error message.
|
29
|
+
#
|
30
|
+
# @since 2.5.0
|
31
|
+
def initialize(message)
|
32
|
+
super(message)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Copyright (C) 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
|
+
class Error
|
17
|
+
|
18
|
+
# Raised if a change stream document is returned without a resume token.
|
19
|
+
#
|
20
|
+
# @since 2.5.0
|
21
|
+
class MissingResumeToken < Error
|
22
|
+
|
23
|
+
# The error message.
|
24
|
+
#
|
25
|
+
# @since 2.5.0
|
26
|
+
MESSAGE = 'Cannot provide resume functionality when the resume token is missing'.freeze
|
27
|
+
|
28
|
+
# Create the new exception.
|
29
|
+
#
|
30
|
+
# @example Create the new exception.
|
31
|
+
# Mongo::Error::MissingResumeToken.new
|
32
|
+
#
|
33
|
+
# @since 2.5.0
|
34
|
+
def initialize
|
35
|
+
super(MESSAGE)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -19,6 +19,7 @@ module Mongo
|
|
19
19
|
#
|
20
20
|
# @since 2.0.0
|
21
21
|
class OperationFailure < Error
|
22
|
+
extend Forwardable
|
22
23
|
|
23
24
|
# These are magic error messages that could indicate a master change.
|
24
25
|
#
|
@@ -49,6 +50,8 @@ module Mongo
|
|
49
50
|
'dbclient error communicating with server'
|
50
51
|
].freeze
|
51
52
|
|
53
|
+
def_delegators :@result, :operation_time
|
54
|
+
|
52
55
|
# Can the read operation that caused the error be retried?
|
53
56
|
#
|
54
57
|
# @example Is the error retryable?
|
@@ -72,6 +75,20 @@ module Mongo
|
|
72
75
|
def write_retryable?
|
73
76
|
WRITE_RETRY_MESSAGES.any? { |m| message.include?(m) }
|
74
77
|
end
|
78
|
+
|
79
|
+
# Create the operation failure.
|
80
|
+
#
|
81
|
+
# @example Create the error object
|
82
|
+
# OperationFailure.new(message, result)
|
83
|
+
#
|
84
|
+
# param [ String ] message The error message.
|
85
|
+
# param [ Operation::Result ] result The result object.
|
86
|
+
#
|
87
|
+
# @since 2.5.0
|
88
|
+
def initialize(message = nil, result = nil)
|
89
|
+
@result = result
|
90
|
+
super(message)
|
91
|
+
end
|
75
92
|
end
|
76
93
|
end
|
77
94
|
end
|
data/lib/mongo/error/parser.rb
CHANGED
@@ -27,7 +27,7 @@ module Mongo
|
|
27
27
|
# @return [ String ] message The error message parsed from the document.
|
28
28
|
attr_reader :message
|
29
29
|
|
30
|
-
# @return [ Array<Protocol::
|
30
|
+
# @return [ Array<Protocol::Message> ] replies The message replies.
|
31
31
|
attr_reader :replies
|
32
32
|
|
33
33
|
# Create the new parser with the returned document.
|
@@ -72,7 +72,8 @@ module Mongo
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def parse_flag(message)
|
75
|
-
if replies && replies.first &&
|
75
|
+
if replies && replies.first &&
|
76
|
+
(replies.first.respond_to?(:cursor_not_found?)) && replies.first.cursor_not_found?
|
76
77
|
append(message, CURSOR_NOT_FOUND)
|
77
78
|
end
|
78
79
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Copyright (C) 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
|
+
class Error
|
17
|
+
|
18
|
+
# Raised if an unknown payload type is encountered when an OP_MSG is created or read.
|
19
|
+
#
|
20
|
+
# @since 2.5.0
|
21
|
+
class UnknownPayloadType < Error
|
22
|
+
|
23
|
+
# The error message.
|
24
|
+
#
|
25
|
+
# @since 2.5.0
|
26
|
+
MESSAGE = 'Unknown payload type (%s) encountered when creating or reading an OP_MSG wire protocol message.'
|
27
|
+
|
28
|
+
# Create the new exception.
|
29
|
+
#
|
30
|
+
# @example Create the new exception.
|
31
|
+
# Mongo::Error::UnknownPayloadType.new(byte)
|
32
|
+
#
|
33
|
+
# @param [ String ] byte The unknown payload type.
|
34
|
+
#
|
35
|
+
# @since 2.5.0
|
36
|
+
def initialize(byte)
|
37
|
+
super(MESSAGE % byte.inspect)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,51 @@
|
|
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
|
+
class Error
|
17
|
+
|
18
|
+
# Raised if the array filters option is specified for an operation but the server
|
19
|
+
# selected does not support array filters.
|
20
|
+
#
|
21
|
+
# @since 2.5.0
|
22
|
+
class UnsupportedArrayFilters < Error
|
23
|
+
|
24
|
+
# The default error message describing that array filters are not supported.
|
25
|
+
#
|
26
|
+
# @return [ String ] A default message describing that array filters are not supported by the server.
|
27
|
+
#
|
28
|
+
# @since 2.5.0
|
29
|
+
DEFAULT_MESSAGE = "The array_filters option is not a supported feature of the server handling this operation. " +
|
30
|
+
"Operation results may be unexpected.".freeze
|
31
|
+
|
32
|
+
# The error message describing that array filters cannot be used when write concern is unacknowledged.
|
33
|
+
#
|
34
|
+
# @return [ String ] A message describing that array filters cannot be used when write concern is unacknowledged.
|
35
|
+
#
|
36
|
+
# @since 2.5.0
|
37
|
+
UNACKNOWLEDGED_WRITES_MESSAGE = "The array_filters option cannot be specified when using unacknowledged writes. " +
|
38
|
+
"Either remove the array_filters option or use acknowledged writes (w >= 1).".freeze
|
39
|
+
|
40
|
+
# Create the new exception.
|
41
|
+
#
|
42
|
+
# @example Create the new exception.
|
43
|
+
# Mongo::Error::UnsupportedArrayFilters.new
|
44
|
+
#
|
45
|
+
# @since 2.5.0
|
46
|
+
def initialize(message = nil)
|
47
|
+
super(message || DEFAULT_MESSAGE)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,23 @@
|
|
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
|
+
class Error
|
17
|
+
|
18
|
+
# Raised when trying to get a message type from the registry that doesn't exist.
|
19
|
+
#
|
20
|
+
# @since 2.5.0
|
21
|
+
class UnsupportedMessageType < Error; end
|
22
|
+
end
|
23
|
+
end
|
data/lib/mongo/grid/fs_bucket.rb
CHANGED
@@ -84,7 +84,8 @@ module Mongo
|
|
84
84
|
#
|
85
85
|
# @since 2.1.0
|
86
86
|
def find(selector = nil, options = {})
|
87
|
-
|
87
|
+
opts = options.merge(read: read_preference) if read_preference
|
88
|
+
files_collection.find(selector, opts || options)
|
88
89
|
end
|
89
90
|
|
90
91
|
# Find a file in the GridFS.
|
@@ -194,8 +195,8 @@ module Mongo
|
|
194
195
|
#
|
195
196
|
# @since 2.1.0
|
196
197
|
def delete(id)
|
197
|
-
result = files_collection.find(:_id => id).delete_one
|
198
|
-
chunks_collection.find(:files_id => id).delete_many
|
198
|
+
result = files_collection.find({ :_id => id }, @options).delete_one
|
199
|
+
chunks_collection.find({ :files_id => id }, @options).delete_many
|
199
200
|
raise Error::FileNotFound.new(id, :id) if result.n == 0
|
200
201
|
result
|
201
202
|
end
|
@@ -409,7 +410,7 @@ module Mongo
|
|
409
410
|
#
|
410
411
|
# @since 2.1.0
|
411
412
|
def read_preference
|
412
|
-
@read_preference ||=
|
413
|
+
@read_preference ||= options[:read] || database.read_preference
|
413
414
|
end
|
414
415
|
|
415
416
|
# Get the write concern.
|