mongo 2.1.2 → 2.2.0.rc0
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 +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +10 -3
- data/Rakefile +1 -7
- data/lib/csasl/csasl.bundle +0 -0
- data/lib/mongo/auth/user/view.rb +1 -1
- data/lib/mongo/bulk_write.rb +7 -1
- data/lib/mongo/client.rb +17 -15
- data/lib/mongo/cluster.rb +4 -2
- data/lib/mongo/collection.rb +36 -2
- data/lib/mongo/collection/view.rb +24 -21
- data/lib/mongo/collection/view/aggregation.rb +5 -42
- data/lib/mongo/collection/view/builder.rb +20 -0
- data/lib/mongo/collection/view/builder/aggregation.rb +98 -0
- data/lib/mongo/collection/view/builder/find_command.rb +111 -0
- data/lib/mongo/collection/view/builder/flags.rb +62 -0
- data/lib/mongo/collection/view/builder/map_reduce.rb +134 -0
- data/lib/mongo/collection/view/builder/modifiers.rb +80 -0
- data/lib/mongo/collection/view/builder/op_query.rb +83 -0
- data/lib/mongo/collection/view/explainable.rb +15 -0
- data/lib/mongo/collection/view/immutable.rb +5 -12
- data/lib/mongo/collection/view/iterable.rb +24 -2
- data/lib/mongo/collection/view/map_reduce.rb +18 -27
- data/lib/mongo/collection/view/readable.rb +70 -112
- data/lib/mongo/collection/view/writable.rb +23 -7
- data/lib/mongo/cursor.rb +76 -25
- data/lib/mongo/cursor/builder.rb +18 -0
- data/lib/mongo/cursor/builder/get_more_command.rb +71 -0
- data/lib/mongo/cursor/builder/kill_cursors_command.rb +62 -0
- data/lib/mongo/cursor/builder/op_get_more.rb +61 -0
- data/lib/mongo/cursor/builder/op_kill_cursors.rb +56 -0
- data/lib/mongo/database.rb +2 -2
- data/lib/mongo/database/view.rb +9 -5
- data/lib/mongo/dbref.rb +3 -3
- data/lib/mongo/error.rb +1 -0
- data/lib/mongo/error/invalid_write_concern.rb +35 -0
- data/lib/mongo/grid/file/chunk.rb +2 -2
- data/lib/mongo/index/view.rb +5 -2
- data/lib/mongo/operation.rb +1 -0
- data/lib/mongo/operation/commands.rb +2 -0
- data/lib/mongo/operation/commands/aggregate.rb +39 -45
- data/lib/mongo/operation/commands/aggregate/result.rb +54 -68
- data/lib/mongo/operation/commands/collections_info.rb +38 -36
- data/lib/mongo/operation/commands/collections_info/result.rb +17 -15
- data/lib/mongo/operation/commands/command.rb +24 -22
- data/lib/mongo/operation/commands/find.rb +27 -0
- data/lib/mongo/operation/commands/find/result.rb +62 -0
- data/lib/mongo/operation/commands/get_more.rb +27 -0
- data/lib/mongo/operation/commands/get_more/result.rb +62 -0
- data/lib/mongo/operation/commands/indexes.rb +41 -39
- data/lib/mongo/operation/commands/list_collections.rb +25 -31
- data/lib/mongo/operation/commands/list_collections/result.rb +63 -81
- data/lib/mongo/operation/commands/list_indexes.rb +27 -35
- data/lib/mongo/operation/commands/list_indexes/result.rb +67 -85
- data/lib/mongo/operation/commands/map_reduce.rb +29 -37
- data/lib/mongo/operation/commands/map_reduce/result.rb +85 -88
- data/lib/mongo/operation/commands/parallel_scan.rb +29 -33
- data/lib/mongo/operation/commands/parallel_scan/result.rb +34 -42
- data/lib/mongo/operation/commands/user_query.rb +40 -38
- data/lib/mongo/operation/commands/users_info.rb +24 -29
- data/lib/mongo/operation/commands/users_info/result.rb +13 -11
- data/lib/mongo/operation/object_id_generator.rb +36 -0
- data/lib/mongo/operation/result.rb +30 -0
- data/lib/mongo/operation/specifiable.rb +35 -1
- data/lib/mongo/operation/write/bulk/bulkable.rb +4 -3
- data/lib/mongo/operation/write/bulk/delete/result.rb +18 -25
- data/lib/mongo/operation/write/bulk/legacy_mergable.rb +2 -2
- data/lib/mongo/operation/write/command/delete.rb +3 -2
- data/lib/mongo/operation/write/command/insert.rb +4 -2
- data/lib/mongo/operation/write/command/update.rb +6 -3
- data/lib/mongo/operation/write/gle.rb +2 -1
- data/lib/mongo/operation/write/idable.rb +19 -2
- data/lib/mongo/options/mapper.rb +22 -0
- data/lib/mongo/protocol/bit_vector.rb +3 -3
- data/lib/mongo/protocol/delete.rb +15 -5
- data/lib/mongo/protocol/get_more.rb +10 -5
- data/lib/mongo/protocol/insert.rb +1 -6
- data/lib/mongo/protocol/kill_cursors.rb +14 -1
- data/lib/mongo/protocol/message.rb +32 -8
- data/lib/mongo/protocol/serializers.rb +15 -16
- data/lib/mongo/protocol/update.rb +35 -12
- data/lib/mongo/server/connectable.rb +3 -1
- data/lib/mongo/server/connection.rb +5 -5
- data/lib/mongo/server/description.rb +8 -2
- data/lib/mongo/server/description/features.rb +2 -1
- data/lib/mongo/server/monitor.rb +1 -12
- data/lib/mongo/server/monitor/connection.rb +30 -26
- data/lib/mongo/server_selector/selectable.rb +21 -4
- data/lib/mongo/uri.rb +2 -0
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo/write_concern.rb +21 -6
- data/mongo.gemspec +1 -2
- data/spec/mongo/bulk_write/ordered_combiner_spec.rb +13 -0
- data/spec/mongo/bulk_write_spec.rb +58 -0
- data/spec/mongo/client_spec.rb +6 -4
- data/spec/mongo/collection/view/builder/find_command_spec.rb +167 -0
- data/spec/mongo/collection/view/builder/flags_spec.rb +106 -0
- data/spec/mongo/collection/view/builder/modifiers_spec.rb +210 -0
- data/spec/mongo/collection/view/builder/op_query_spec.rb +154 -0
- data/spec/mongo/collection/view/explainable_spec.rb +1 -2
- data/spec/mongo/collection/view/immutable_spec.rb +3 -52
- data/spec/mongo/collection/view/map_reduce_spec.rb +12 -12
- data/spec/mongo/collection/view/readable_spec.rb +86 -80
- data/spec/mongo/collection/view_spec.rb +109 -703
- data/spec/mongo/collection_spec.rb +594 -11
- data/spec/mongo/command_monitoring_spec.rb +40 -27
- data/spec/mongo/cursor/builder/get_more_command_spec.rb +160 -0
- data/spec/mongo/cursor/builder/op_get_more_spec.rb +52 -0
- data/spec/mongo/cursor_spec.rb +10 -60
- data/spec/mongo/database_spec.rb +24 -3
- data/spec/mongo/dbref_spec.rb +4 -4
- data/spec/mongo/grid/file/chunk_spec.rb +1 -1
- data/spec/mongo/grid/fs_bucket_spec.rb +3 -3
- data/spec/mongo/index/view_spec.rb +41 -0
- data/spec/mongo/operation/{aggregate → commands/aggregate}/result_spec.rb +1 -1
- data/spec/mongo/operation/commands/aggregate_spec.rb +1 -1
- data/spec/mongo/operation/commands/collections_info_spec.rb +1 -1
- data/spec/mongo/operation/commands/command_spec.rb +1 -1
- data/spec/mongo/operation/commands/indexes_spec.rb +1 -1
- data/spec/mongo/operation/commands/map_reduce_spec.rb +1 -1
- data/spec/mongo/operation/write/command/delete_spec.rb +25 -0
- data/spec/mongo/operation/write/command/insert_spec.rb +25 -0
- data/spec/mongo/operation/write/command/update_spec.rb +25 -0
- data/spec/mongo/protocol/delete_spec.rb +4 -4
- data/spec/mongo/protocol/get_more_spec.rb +4 -4
- data/spec/mongo/protocol/insert_spec.rb +3 -3
- data/spec/mongo/protocol/kill_cursors_spec.rb +3 -3
- data/spec/mongo/protocol/query_spec.rb +7 -7
- data/spec/mongo/protocol/update_spec.rb +5 -5
- data/spec/mongo/server/description/features_spec.rb +25 -0
- data/spec/mongo/write_concern_spec.rb +126 -0
- data/spec/spec_helper.rb +9 -19
- data/spec/support/command_monitoring.rb +8 -0
- data/spec/support/command_monitoring/find.yml +53 -4
- data/spec/support/matchers.rb +1 -1
- data/spec/support/shared/protocol.rb +5 -5
- data/spec/support/travis.rb +1 -1
- metadata +43 -10
- metadata.gz.sig +0 -0
@@ -14,107 +14,104 @@
|
|
14
14
|
|
15
15
|
module Mongo
|
16
16
|
module Operation
|
17
|
-
|
17
|
+
module Commands
|
18
|
+
class MapReduce
|
18
19
|
|
19
|
-
|
20
|
-
#
|
21
|
-
# @since 2.0.0
|
22
|
-
class Result < Operation::Result
|
23
|
-
|
24
|
-
# The counts field for the map/reduce.
|
20
|
+
# Defines custom behaviour of results for a map reduce operation.
|
25
21
|
#
|
26
22
|
# @since 2.0.0
|
27
|
-
|
23
|
+
class Result < Operation::Result
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
25
|
+
# The counts field for the map/reduce.
|
26
|
+
#
|
27
|
+
# @since 2.0.0
|
28
|
+
COUNTS = 'counts'.freeze
|
33
29
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
# The field name for a result without a cursor.
|
31
|
+
#
|
32
|
+
# @since 2.0.0
|
33
|
+
RESULTS = 'results'.freeze
|
38
34
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
# The time the operation took constant.
|
36
|
+
#
|
37
|
+
# @since 2.0.0
|
38
|
+
TIME = 'timeMillis'.freeze
|
43
39
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
40
|
+
# Gets the map/reduce counts from the reply.
|
41
|
+
#
|
42
|
+
# @example Get the counts.
|
43
|
+
# result.counts
|
44
|
+
#
|
45
|
+
# @return [ Hash ] A hash of the result counts.
|
46
|
+
#
|
47
|
+
# @since 2.0.0
|
48
|
+
def counts
|
49
|
+
reply.documents[0][COUNTS]
|
50
|
+
end
|
55
51
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
52
|
+
# Get the documents from the map/reduce.
|
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][RESULTS] || reply.documents[0][RESULT]
|
62
|
+
end
|
67
63
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
64
|
+
# If the result was a command then determine if it was considered a
|
65
|
+
# success.
|
66
|
+
#
|
67
|
+
# @note If the write was unacknowledged, then this will always return
|
68
|
+
# true.
|
69
|
+
#
|
70
|
+
# @example Was the command successful?
|
71
|
+
# result.successful?
|
72
|
+
#
|
73
|
+
# @return [ true, false ] If the command was successful.
|
74
|
+
#
|
75
|
+
# @since 2.0.0
|
76
|
+
def successful?
|
77
|
+
!documents.nil?
|
78
|
+
end
|
83
79
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
80
|
+
# Get the execution time of the map/reduce.
|
81
|
+
#
|
82
|
+
# @example Get the execution time.
|
83
|
+
# result.time
|
84
|
+
#
|
85
|
+
# @return [ Integer ] The executiong time in milliseconds.
|
86
|
+
#
|
87
|
+
# @since 2.0.0
|
88
|
+
def time
|
89
|
+
reply.documents[0][TIME]
|
90
|
+
end
|
95
91
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
92
|
+
# Validate the result by checking for any errors.
|
93
|
+
#
|
94
|
+
# @note This only checks for errors with writes since authentication is
|
95
|
+
# handled at the connection level and any authentication errors would
|
96
|
+
# be raised there, before a Result is ever created.
|
97
|
+
#
|
98
|
+
# @example Validate the result.
|
99
|
+
# result.validate!
|
100
|
+
#
|
101
|
+
# @raise [ Error::OperationFailure ] If an error is in the result.
|
102
|
+
#
|
103
|
+
# @return [ Result ] The result if verification passed.
|
104
|
+
#
|
105
|
+
# @since 2.0.0
|
106
|
+
def validate!
|
107
|
+
documents.nil? ? raise(Error::OperationFailure.new(parser.message)) : self
|
108
|
+
end
|
113
109
|
|
114
|
-
|
110
|
+
private
|
115
111
|
|
116
|
-
|
117
|
-
|
112
|
+
def first_document
|
113
|
+
@first_document ||= reply.documents[0]
|
114
|
+
end
|
118
115
|
end
|
119
116
|
end
|
120
117
|
end
|
@@ -12,45 +12,41 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require 'mongo/operation/commands/parallel_scan/result'
|
16
|
-
|
17
15
|
module Mongo
|
18
16
|
module Operation
|
17
|
+
module Commands
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
include Specifiable
|
41
|
-
include Limited
|
42
|
-
include ReadPreference
|
43
|
-
include Executable
|
44
|
-
|
45
|
-
private
|
19
|
+
# A MongoDB parallel scan operation.
|
20
|
+
#
|
21
|
+
# @example Create the parallel scan operation.
|
22
|
+
# ParallelScan.new({
|
23
|
+
# :db_name => 'test_db',
|
24
|
+
# :coll_name = > 'test_collection',
|
25
|
+
# :cursor_count => 5
|
26
|
+
# })
|
27
|
+
#
|
28
|
+
# Initialization:
|
29
|
+
# param [ Hash ] spec The specifications for the operation.
|
30
|
+
#
|
31
|
+
# option spec :db_name [ String ] The name of the database on which
|
32
|
+
# the operation should be executed.
|
33
|
+
# option spec :coll_name [ String ] The collection to scan.
|
34
|
+
# option spec :cursor_count [ Integer ] The number of cursors to use.
|
35
|
+
# option spec :options [ Hash ] Options for the command.
|
36
|
+
#
|
37
|
+
# @since 2.0.0
|
38
|
+
class ParallelScan < Command
|
46
39
|
|
47
|
-
|
48
|
-
{ :parallelCollectionScan => coll_name, :numCursors => cursor_count }
|
49
|
-
end
|
40
|
+
private
|
50
41
|
|
51
|
-
|
52
|
-
|
42
|
+
def selector
|
43
|
+
command = { :parallelCollectionScan => coll_name, :numCursors => cursor_count }
|
44
|
+
command[:readConcern] = read_concern if read_concern
|
45
|
+
command
|
46
|
+
end
|
53
47
|
end
|
54
48
|
end
|
55
49
|
end
|
56
50
|
end
|
51
|
+
|
52
|
+
require 'mongo/operation/commands/parallel_scan/result'
|
@@ -15,56 +15,48 @@
|
|
15
15
|
|
16
16
|
module Mongo
|
17
17
|
module Operation
|
18
|
-
|
18
|
+
module Commands
|
19
|
+
class ParallelScan
|
19
20
|
|
20
|
-
|
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.
|
21
|
+
# Defines custom behaviour of results in a parallel scan.
|
31
22
|
#
|
32
23
|
# @since 2.0.0
|
33
|
-
|
24
|
+
class Result < Operation::Result
|
34
25
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
26
|
+
# The name of the cursors field in the result.
|
27
|
+
#
|
28
|
+
# @since 2.0.0
|
29
|
+
CURSORS = 'cursors'.freeze
|
39
30
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
31
|
+
# Get all the cursor ids from the result.
|
32
|
+
#
|
33
|
+
# @example Get the cursor ids.
|
34
|
+
# result.cursor_ids
|
35
|
+
#
|
36
|
+
# @return [ Array<Integer> ] The cursor ids.
|
37
|
+
#
|
38
|
+
# @since 2.0.0
|
39
|
+
def cursor_ids
|
40
|
+
documents.map{ |doc| doc[CURSOR][CURSOR_ID] }
|
41
|
+
end
|
51
42
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
43
|
+
# Get the documents from parallel scan.
|
44
|
+
#
|
45
|
+
# @example Get the documents.
|
46
|
+
# result.documents
|
47
|
+
#
|
48
|
+
# @return [ Array<BSON::Document> ] The documents.
|
49
|
+
#
|
50
|
+
# @since 2.0.0
|
51
|
+
def documents
|
52
|
+
reply.documents[0][CURSORS]
|
53
|
+
end
|
63
54
|
|
64
|
-
|
55
|
+
private
|
65
56
|
|
66
|
-
|
67
|
-
|
57
|
+
def first
|
58
|
+
@first ||= reply.documents[0] || {}
|
59
|
+
end
|
68
60
|
end
|
69
61
|
end
|
70
62
|
end
|
@@ -14,55 +14,57 @@
|
|
14
14
|
|
15
15
|
module Mongo
|
16
16
|
module Operation
|
17
|
+
module Commands
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
#
|
23
|
-
# Initialization:
|
24
|
-
# param [ Hash ] spec The specifications for the user query operation.
|
25
|
-
#
|
26
|
-
# option spec :user_name [ String ] The name of the user.
|
27
|
-
# option spec :db_name [ String ] The name of the database where the user exists.
|
28
|
-
# option spec :options [ Hash ] Options for the operation.
|
29
|
-
#
|
30
|
-
# @since 2.1.0
|
31
|
-
class UserQuery
|
32
|
-
include Executable
|
33
|
-
include Specifiable
|
34
|
-
|
35
|
-
# Execute the operation.
|
36
|
-
# The context gets a connection on which the operation
|
37
|
-
# is sent in the block.
|
19
|
+
# A MongoDB operation to get info of a particular user in a database.
|
20
|
+
#
|
21
|
+
# @example Create the user query operation.
|
22
|
+
# Read::UserQuery.new(:name => 'emily', :db_name => 'test-db')
|
38
23
|
#
|
39
|
-
#
|
24
|
+
# Initialization:
|
25
|
+
# param [ Hash ] spec The specifications for the user query operation.
|
40
26
|
#
|
41
|
-
#
|
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.
|
42
30
|
#
|
43
31
|
# @since 2.1.0
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
32
|
+
class UserQuery
|
33
|
+
include Executable
|
34
|
+
include Specifiable
|
35
|
+
|
36
|
+
# Execute the operation.
|
37
|
+
# The context gets a connection on which the operation
|
38
|
+
# is sent in the block.
|
39
|
+
#
|
40
|
+
# @param [ Mongo::Server::Context ] context The context for this operation.
|
41
|
+
#
|
42
|
+
# @return [ Result ] The operation response, if there is one.
|
43
|
+
#
|
44
|
+
# @since 2.1.0
|
45
|
+
def execute(context)
|
46
|
+
if context.features.users_info_enabled?
|
47
|
+
UsersInfo.new(spec).execute(context)
|
48
|
+
else
|
49
|
+
context.with_connection do |connection|
|
50
|
+
Result.new(connection.dispatch([ message(context) ])).validate!
|
51
|
+
end
|
50
52
|
end
|
51
53
|
end
|
52
|
-
end
|
53
54
|
|
54
|
-
|
55
|
+
private
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
def selector
|
58
|
+
{ :user => user_name }
|
59
|
+
end
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
61
|
+
def query_coll
|
62
|
+
Auth::User::COLLECTION
|
63
|
+
end
|
63
64
|
|
64
|
-
|
65
|
-
|
65
|
+
def message(context)
|
66
|
+
Protocol::Query.new(db_name, query_coll, selector, options)
|
67
|
+
end
|
66
68
|
end
|
67
69
|
end
|
68
70
|
end
|