mongo 2.0.6 → 2.1.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mongo.rb +2 -0
- data/lib/mongo/bulk_write.rb +1 -0
- data/lib/mongo/bulk_write/bulk_writable.rb +87 -31
- data/lib/mongo/bulk_write/deletable.rb +8 -7
- data/lib/mongo/bulk_write/insertable.rb +4 -3
- data/lib/mongo/bulk_write/ordered_bulk_write.rb +6 -6
- data/lib/mongo/bulk_write/replacable.rb +4 -3
- data/lib/mongo/bulk_write/result.rb +138 -0
- data/lib/mongo/bulk_write/unordered_bulk_write.rb +5 -8
- data/lib/mongo/bulk_write/updatable.rb +8 -7
- data/lib/mongo/client.rb +36 -4
- data/lib/mongo/cluster.rb +39 -4
- data/lib/mongo/cluster/topology/replica_set.rb +20 -4
- data/lib/mongo/cluster/topology/sharded.rb +1 -1
- data/lib/mongo/collection.rb +282 -29
- data/lib/mongo/collection/view/aggregation.rb +32 -4
- data/lib/mongo/collection/view/iterable.rb +2 -1
- data/lib/mongo/collection/view/map_reduce.rb +3 -1
- data/lib/mongo/collection/view/readable.rb +89 -14
- data/lib/mongo/collection/view/writable.rb +11 -5
- data/lib/mongo/cursor.rb +11 -3
- data/lib/mongo/dbref.rb +113 -0
- data/lib/mongo/error.rb +6 -2
- data/lib/mongo/error/parser.rb +1 -1
- data/lib/mongo/event/description_changed.rb +1 -1
- data/lib/mongo/grid/file.rb +1 -1
- data/lib/mongo/grid/fs.rb +2 -5
- data/lib/mongo/monitoring.rb +199 -0
- data/lib/mongo/monitoring/command_log_subscriber.rb +88 -0
- data/lib/mongo/monitoring/event.rb +17 -0
- data/lib/mongo/monitoring/event/command_failed.rb +96 -0
- data/lib/mongo/monitoring/event/command_started.rb +88 -0
- data/lib/mongo/monitoring/event/command_succeeded.rb +96 -0
- data/lib/mongo/monitoring/publishable.rb +96 -0
- data/lib/mongo/operation.rb +1 -0
- data/lib/mongo/operation/executable.rb +1 -1
- data/lib/mongo/operation/parallel_scan.rb +76 -0
- data/lib/mongo/operation/parallel_scan/result.rb +72 -0
- data/lib/mongo/operation/specifiable.rb +18 -0
- data/lib/mongo/operation/write/bulk/bulk_delete.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulk_insert.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulk_mergable.rb +2 -2
- data/lib/mongo/operation/write/bulk/bulk_update.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulk_update/result.rb +13 -1
- data/lib/mongo/protocol/delete.rb +8 -13
- data/lib/mongo/protocol/get_more.rb +13 -13
- data/lib/mongo/protocol/insert.rb +8 -13
- data/lib/mongo/protocol/kill_cursors.rb +7 -11
- data/lib/mongo/protocol/query.rb +58 -20
- data/lib/mongo/protocol/reply.rb +12 -0
- data/lib/mongo/protocol/update.rb +13 -14
- data/lib/mongo/server.rb +23 -2
- data/lib/mongo/server/connectable.rb +0 -22
- data/lib/mongo/server/connection.rb +29 -0
- data/lib/mongo/server/description.rb +23 -1
- data/lib/mongo/server/monitor.rb +17 -1
- data/lib/mongo/server/monitor/connection.rb +24 -0
- data/lib/mongo/socket/ssl.rb +28 -16
- data/lib/mongo/socket/tcp.rb +1 -1
- data/lib/mongo/socket/unix.rb +1 -1
- data/lib/mongo/uri.rb +12 -5
- data/lib/mongo/version.rb +1 -1
- data/spec/mongo/auth/cr_spec.rb +9 -1
- data/spec/mongo/auth/ldap_spec.rb +9 -1
- data/spec/mongo/auth/scram_spec.rb +9 -1
- data/spec/mongo/auth/x509_spec.rb +9 -1
- data/spec/mongo/{bulk/bulk_write_spec.rb → bulk_write_spec.rb} +15 -15
- data/spec/mongo/client_spec.rb +42 -0
- data/spec/mongo/cluster/topology/replica_set_spec.rb +16 -9
- data/spec/mongo/cluster/topology/sharded_spec.rb +11 -3
- data/spec/mongo/cluster/topology/single_spec.rb +12 -4
- data/spec/mongo/cluster_spec.rb +55 -10
- data/spec/mongo/collection/view/aggregation_spec.rb +123 -1
- data/spec/mongo/collection/view/explainable_spec.rb +1 -1
- data/spec/mongo/collection/view/map_reduce_spec.rb +1 -1
- data/spec/mongo/collection/view/readable_spec.rb +251 -6
- data/spec/mongo/collection/view/writable_spec.rb +4 -4
- data/spec/mongo/collection/view_spec.rb +233 -71
- data/spec/mongo/collection_spec.rb +905 -9
- data/spec/mongo/crud_spec.rb +2 -2
- data/spec/mongo/cursor_spec.rb +3 -3
- data/spec/mongo/dbref_spec.rb +149 -0
- data/spec/mongo/monitoring_spec.rb +168 -0
- data/spec/mongo/operation/map_reduce_spec.rb +1 -1
- data/spec/mongo/operation/write/bulk/bulk_delete_spec.rb +1 -1
- data/spec/mongo/operation/write/bulk/bulk_insert_spec.rb +2 -2
- data/spec/mongo/operation/write/bulk/bulk_update_spec.rb +1 -1
- data/spec/mongo/operation/write/delete_spec.rb +1 -1
- data/spec/mongo/operation/write/insert_spec.rb +2 -2
- data/spec/mongo/operation/write/update_spec.rb +1 -1
- data/spec/mongo/protocol/query_spec.rb +0 -29
- data/spec/mongo/server/connection_pool_spec.rb +18 -6
- data/spec/mongo/server/connection_spec.rb +12 -4
- data/spec/mongo/server/description_spec.rb +7 -3
- data/spec/mongo/server/monitor_spec.rb +30 -0
- data/spec/mongo/server_discovery_and_monitoring_spec.rb +11 -4
- data/spec/mongo/server_selection_spec.rb +14 -6
- data/spec/mongo/server_spec.rb +27 -8
- data/spec/mongo/socket/ssl_spec.rb +94 -8
- data/spec/mongo/uri_spec.rb +25 -9
- data/spec/spec_helper.rb +29 -20
- data/spec/support/authorization.rb +19 -4
- data/spec/support/certificates/client.pem +4 -4
- data/spec/support/crud/read.rb +9 -10
- data/spec/support/crud/write.rb +24 -20
- data/spec/support/sdam/rs/equal_electionids.yml +45 -0
- data/spec/support/sdam/rs/new_primary_new_electionid.yml +98 -0
- data/spec/support/sdam/rs/null_election_id.yml +144 -0
- data/spec/support/sdam/rs/primary_disconnect_electionid.yml +124 -0
- data/spec/support/sdam/sharded/mongos_disconnect.yml +104 -0
- data/spec/support/server_discovery_and_monitoring.rb +19 -2
- data/spec/support/shared/bulk_write.rb +26 -22
- data/spec/support/shared/server_selector.rb +2 -1
- metadata +31 -7
- metadata.gz.sig +0 -0
- data/lib/mongo/error/invalid_uri_option.rb +0 -38
@@ -0,0 +1,88 @@
|
|
1
|
+
# Copyright (C) 2015 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 Monitoring
|
17
|
+
module Event
|
18
|
+
|
19
|
+
# Event that is fired when a command operation starts.
|
20
|
+
#
|
21
|
+
# @since 2.1.0
|
22
|
+
class CommandStarted
|
23
|
+
|
24
|
+
# @return [ Server::Address ] address The server address.
|
25
|
+
attr_reader :address
|
26
|
+
|
27
|
+
# @return [ BSON::Document ] command The command arguments.
|
28
|
+
attr_reader :command
|
29
|
+
|
30
|
+
# @return [ String ] command_name The name of the command.
|
31
|
+
attr_reader :command_name
|
32
|
+
|
33
|
+
# @return [ String ] database_name The name of the database_name.
|
34
|
+
attr_reader :database_name
|
35
|
+
|
36
|
+
# @return [ Integer ] operation_id The operation id.
|
37
|
+
attr_reader :operation_id
|
38
|
+
|
39
|
+
# @return [ Integer ] request_id The request id.
|
40
|
+
attr_reader :request_id
|
41
|
+
|
42
|
+
# Create the new event.
|
43
|
+
#
|
44
|
+
# @example Create the event.
|
45
|
+
#
|
46
|
+
# @param [ String ] command_name The name of the command.
|
47
|
+
# @param [ String ] database_name The database_name name.
|
48
|
+
# @param [ Server::Address ] address The server address.
|
49
|
+
# @param [ Integer ] request_id The request id.
|
50
|
+
# @param [ Integer ] operation_id The operation id.
|
51
|
+
# @param [ BSON::Document ] command The command arguments.
|
52
|
+
#
|
53
|
+
# @since 2.1.0
|
54
|
+
def initialize(command_name, database_name, address, request_id, operation_id, command)
|
55
|
+
@command_name = command_name
|
56
|
+
@database_name = database_name
|
57
|
+
@address = address
|
58
|
+
@request_id = request_id
|
59
|
+
@operation_id = operation_id
|
60
|
+
@command = command
|
61
|
+
end
|
62
|
+
|
63
|
+
# Create the event from a wire protocol message payload.
|
64
|
+
#
|
65
|
+
# @example Create the event.
|
66
|
+
# CommandStarted.generate(address, 1, payload)
|
67
|
+
#
|
68
|
+
# @param [ Server::Address ] address The server address.
|
69
|
+
# @param [ Integer ] operation_id The operation id.
|
70
|
+
# @param [ Hash ] payload The message payload.
|
71
|
+
#
|
72
|
+
# @return [ CommandStarted ] The event.
|
73
|
+
#
|
74
|
+
# @since 2.1.0
|
75
|
+
def self.generate(address, operation_id, payload)
|
76
|
+
new(
|
77
|
+
payload[:command_name],
|
78
|
+
payload[:database_name],
|
79
|
+
address,
|
80
|
+
payload[:request_id],
|
81
|
+
operation_id,
|
82
|
+
payload[:command]
|
83
|
+
)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# Copyright (C) 2015 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 Monitoring
|
17
|
+
module Event
|
18
|
+
|
19
|
+
# Event that is fired when a command operation succeeds.
|
20
|
+
#
|
21
|
+
# @since 2.1.0
|
22
|
+
class CommandSucceeded
|
23
|
+
|
24
|
+
# @return [ Server::Address ] address The server address.
|
25
|
+
attr_reader :address
|
26
|
+
|
27
|
+
# @return [ String ] command_name The name of the command.
|
28
|
+
attr_reader :command_name
|
29
|
+
|
30
|
+
# @return [ BSON::Document ] reply The command reply.
|
31
|
+
attr_reader :reply
|
32
|
+
|
33
|
+
# @return [ String ] database_name The name of the database.
|
34
|
+
attr_reader :database_name
|
35
|
+
|
36
|
+
# @return [ Float ] duration The duration of the event.
|
37
|
+
attr_reader :duration
|
38
|
+
|
39
|
+
# @return [ Integer ] operation_id The operation id.
|
40
|
+
attr_reader :operation_id
|
41
|
+
|
42
|
+
# @return [ Integer ] request_id The request id.
|
43
|
+
attr_reader :request_id
|
44
|
+
|
45
|
+
# Create the new event.
|
46
|
+
#
|
47
|
+
# @example Create the event.
|
48
|
+
#
|
49
|
+
# @param [ String ] command_name The name of the command.
|
50
|
+
# @param [ String ] database_name The database name.
|
51
|
+
# @param [ Server::Address ] address The server address.
|
52
|
+
# @param [ Integer ] request_id The request id.
|
53
|
+
# @param [ Integer ] operation_id The operation id.
|
54
|
+
# @param [ BSON::Document ] reply The command reply.
|
55
|
+
# @param [ Float ] duration The duration the command took in seconds.
|
56
|
+
#
|
57
|
+
# @since 2.1.0
|
58
|
+
def initialize(command_name, database_name, address, request_id, operation_id, reply, duration)
|
59
|
+
@command_name = command_name
|
60
|
+
@database_name = database_name
|
61
|
+
@address = address
|
62
|
+
@request_id = request_id
|
63
|
+
@operation_id = operation_id
|
64
|
+
@reply = reply
|
65
|
+
@duration = duration
|
66
|
+
end
|
67
|
+
|
68
|
+
# Create the event from a wire protocol message payload.
|
69
|
+
#
|
70
|
+
# @example Create the event.
|
71
|
+
# CommandSucceeded.generate(address, 1, command_payload, reply_payload, 0.5)
|
72
|
+
#
|
73
|
+
# @param [ Server::Address ] address The server address.
|
74
|
+
# @param [ Integer ] operation_id The operation id.
|
75
|
+
# @param [ Hash ] command_payload The command message payload.
|
76
|
+
# @param [ Hash ] reply_payload The reply message payload.
|
77
|
+
# @param [ Float ] duration The duration of the command in seconds.
|
78
|
+
#
|
79
|
+
# @return [ CommandCompleted ] The event.
|
80
|
+
#
|
81
|
+
# @since 2.1.0
|
82
|
+
def self.generate(address, operation_id, command_payload, reply_payload, duration)
|
83
|
+
new(
|
84
|
+
command_payload[:command_name],
|
85
|
+
command_payload[:database_name],
|
86
|
+
address,
|
87
|
+
command_payload[:request_id],
|
88
|
+
operation_id,
|
89
|
+
reply_payload ? reply_payload[:reply] : nil,
|
90
|
+
duration
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# Copyright (C) 2015 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 Monitoring
|
17
|
+
|
18
|
+
# Defines behaviour for an object that can publish monitoring events.
|
19
|
+
#
|
20
|
+
# @since 2.1.0
|
21
|
+
module Publishable
|
22
|
+
|
23
|
+
# @return [ Monitoring ] monitoring The monitoring.
|
24
|
+
attr_reader :monitoring
|
25
|
+
|
26
|
+
# Publish a command event to the global monitoring.
|
27
|
+
#
|
28
|
+
# @example Publish a command event.
|
29
|
+
# publish_command do |messages|
|
30
|
+
# # ...
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# @param [ Array<Message> ] messages The messages.
|
34
|
+
#
|
35
|
+
# @return [ Object ] The result of the yield.
|
36
|
+
#
|
37
|
+
# @since 2.1.0
|
38
|
+
def publish_command(messages, operation_id = Monitoring.next_operation_id)
|
39
|
+
start = Time.now
|
40
|
+
payload = messages.first.payload
|
41
|
+
command_started(address, operation_id, payload)
|
42
|
+
begin
|
43
|
+
result = yield(messages)
|
44
|
+
command_completed(result, address, operation_id, payload, start)
|
45
|
+
result
|
46
|
+
rescue Exception => e
|
47
|
+
command_failed(address, operation_id, payload, e.message, start)
|
48
|
+
raise e
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def command_started(address, operation_id, payload)
|
55
|
+
monitoring.started(
|
56
|
+
Monitoring::COMMAND,
|
57
|
+
Event::CommandStarted.generate(address, operation_id, payload)
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
def command_completed(result, address, operation_id, payload, start)
|
62
|
+
document = result ? (result.documents || []).first : nil
|
63
|
+
parser = Error::Parser.new(document)
|
64
|
+
if parser.message.empty?
|
65
|
+
command_succeeded(result, address, operation_id, payload, start)
|
66
|
+
else
|
67
|
+
command_failed(address, operation_id, payload, parser.message, start)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def command_succeeded(result, address, operation_id, payload, start)
|
72
|
+
monitoring.succeeded(
|
73
|
+
Monitoring::COMMAND,
|
74
|
+
Event::CommandSucceeded.generate(
|
75
|
+
address,
|
76
|
+
operation_id,
|
77
|
+
payload,
|
78
|
+
result ? result.payload : nil,
|
79
|
+
duration(start)
|
80
|
+
)
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
def command_failed(address, operation_id, payload, message, start)
|
85
|
+
monitoring.failed(
|
86
|
+
Monitoring::COMMAND,
|
87
|
+
Event::CommandFailed.generate(address, operation_id, payload, message, duration(start))
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
91
|
+
def duration(start)
|
92
|
+
Time.now - start
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/mongo/operation.rb
CHANGED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Copyright (C) 2009-2014 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
|
+
require 'mongo/operation/parallel_scan/result'
|
16
|
+
|
17
|
+
module Mongo
|
18
|
+
module Operation
|
19
|
+
|
20
|
+
# A MongoDB parallel scan operation.
|
21
|
+
#
|
22
|
+
# @example Create the parallel scan operation.
|
23
|
+
# ParallelScan.new({
|
24
|
+
# :db_name => 'test_db',
|
25
|
+
# :coll_name = > 'test_collection',
|
26
|
+
# :cursor_count => 5
|
27
|
+
# })
|
28
|
+
#
|
29
|
+
# Initialization:
|
30
|
+
# param [ Hash ] spec The specifications for the operation.
|
31
|
+
#
|
32
|
+
# option spec :db_name [ String ] The name of the database on which
|
33
|
+
# the operation should be executed.
|
34
|
+
# option spec :coll_name [ String ] The collection to scan.
|
35
|
+
# option spec :cursor_count [ Integer ] The number of cursors to use.
|
36
|
+
# option spec :options [ Hash ] Options for the command.
|
37
|
+
#
|
38
|
+
# @since 2.0.0
|
39
|
+
class ParallelScan
|
40
|
+
include Executable
|
41
|
+
include Specifiable
|
42
|
+
include Limited
|
43
|
+
include ReadPreferrable
|
44
|
+
|
45
|
+
# Execute the parallel scan operation.
|
46
|
+
#
|
47
|
+
# @example Execute the operation.
|
48
|
+
# operation.execute(context)
|
49
|
+
#
|
50
|
+
# @param [ Mongo::Server::Context ] context The context for this operation.
|
51
|
+
#
|
52
|
+
# @return [ Result ] The operation response, if there is one.
|
53
|
+
#
|
54
|
+
# @since 2.0.0
|
55
|
+
def execute(context)
|
56
|
+
execute_message(context)
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def execute_message(context)
|
62
|
+
context.with_connection do |connection|
|
63
|
+
Result.new(connection.dispatch([ message(context) ])).validate!
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def selector
|
68
|
+
{ :parallelCollectionScan => coll_name, :numCursors => cursor_count }
|
69
|
+
end
|
70
|
+
|
71
|
+
def query_coll
|
72
|
+
Database::COMMAND
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
|
2
|
+
# Copyright (C) 2009-2014 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
|
+
class ParallelScan
|
19
|
+
|
20
|
+
# Defines custom behaviour of results in a parallel scan.
|
21
|
+
#
|
22
|
+
# @since 2.0.0
|
23
|
+
class Result < Operation::Result
|
24
|
+
|
25
|
+
# Get the name of the cursor field.
|
26
|
+
#
|
27
|
+
# @since 2.0.0
|
28
|
+
CURSOR = 'cursor'.freeze
|
29
|
+
|
30
|
+
# The name of the cursors field in the result.
|
31
|
+
#
|
32
|
+
# @since 2.0.0
|
33
|
+
CURSORS = 'cursors'.freeze
|
34
|
+
|
35
|
+
# Get the name of the id field.
|
36
|
+
#
|
37
|
+
# @since 2.0.0
|
38
|
+
ID = 'id'.freeze
|
39
|
+
|
40
|
+
# Get all the cursor ids from the result.
|
41
|
+
#
|
42
|
+
# @example Get the cursor ids.
|
43
|
+
# result.cursor_ids
|
44
|
+
#
|
45
|
+
# @return [ Array<Integer> ] The cursor ids.
|
46
|
+
#
|
47
|
+
# @since 2.0.0
|
48
|
+
def cursor_ids
|
49
|
+
documents.map{ |doc| doc[CURSOR][ID] }
|
50
|
+
end
|
51
|
+
|
52
|
+
# Get the documents from parallel scan.
|
53
|
+
#
|
54
|
+
# @example Get the documents.
|
55
|
+
# result.documents
|
56
|
+
#
|
57
|
+
# @return [ Array<BSON::Document> ] The documents.
|
58
|
+
#
|
59
|
+
# @since 2.0.0
|
60
|
+
def documents
|
61
|
+
reply.documents[0][CURSORS]
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def first
|
67
|
+
@first ||= reply.documents[0] || {}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|