mongo 2.1.2 → 2.2.0.rc0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +10 -3
  5. data/Rakefile +1 -7
  6. data/lib/csasl/csasl.bundle +0 -0
  7. data/lib/mongo/auth/user/view.rb +1 -1
  8. data/lib/mongo/bulk_write.rb +7 -1
  9. data/lib/mongo/client.rb +17 -15
  10. data/lib/mongo/cluster.rb +4 -2
  11. data/lib/mongo/collection.rb +36 -2
  12. data/lib/mongo/collection/view.rb +24 -21
  13. data/lib/mongo/collection/view/aggregation.rb +5 -42
  14. data/lib/mongo/collection/view/builder.rb +20 -0
  15. data/lib/mongo/collection/view/builder/aggregation.rb +98 -0
  16. data/lib/mongo/collection/view/builder/find_command.rb +111 -0
  17. data/lib/mongo/collection/view/builder/flags.rb +62 -0
  18. data/lib/mongo/collection/view/builder/map_reduce.rb +134 -0
  19. data/lib/mongo/collection/view/builder/modifiers.rb +80 -0
  20. data/lib/mongo/collection/view/builder/op_query.rb +83 -0
  21. data/lib/mongo/collection/view/explainable.rb +15 -0
  22. data/lib/mongo/collection/view/immutable.rb +5 -12
  23. data/lib/mongo/collection/view/iterable.rb +24 -2
  24. data/lib/mongo/collection/view/map_reduce.rb +18 -27
  25. data/lib/mongo/collection/view/readable.rb +70 -112
  26. data/lib/mongo/collection/view/writable.rb +23 -7
  27. data/lib/mongo/cursor.rb +76 -25
  28. data/lib/mongo/cursor/builder.rb +18 -0
  29. data/lib/mongo/cursor/builder/get_more_command.rb +71 -0
  30. data/lib/mongo/cursor/builder/kill_cursors_command.rb +62 -0
  31. data/lib/mongo/cursor/builder/op_get_more.rb +61 -0
  32. data/lib/mongo/cursor/builder/op_kill_cursors.rb +56 -0
  33. data/lib/mongo/database.rb +2 -2
  34. data/lib/mongo/database/view.rb +9 -5
  35. data/lib/mongo/dbref.rb +3 -3
  36. data/lib/mongo/error.rb +1 -0
  37. data/lib/mongo/error/invalid_write_concern.rb +35 -0
  38. data/lib/mongo/grid/file/chunk.rb +2 -2
  39. data/lib/mongo/index/view.rb +5 -2
  40. data/lib/mongo/operation.rb +1 -0
  41. data/lib/mongo/operation/commands.rb +2 -0
  42. data/lib/mongo/operation/commands/aggregate.rb +39 -45
  43. data/lib/mongo/operation/commands/aggregate/result.rb +54 -68
  44. data/lib/mongo/operation/commands/collections_info.rb +38 -36
  45. data/lib/mongo/operation/commands/collections_info/result.rb +17 -15
  46. data/lib/mongo/operation/commands/command.rb +24 -22
  47. data/lib/mongo/operation/commands/find.rb +27 -0
  48. data/lib/mongo/operation/commands/find/result.rb +62 -0
  49. data/lib/mongo/operation/commands/get_more.rb +27 -0
  50. data/lib/mongo/operation/commands/get_more/result.rb +62 -0
  51. data/lib/mongo/operation/commands/indexes.rb +41 -39
  52. data/lib/mongo/operation/commands/list_collections.rb +25 -31
  53. data/lib/mongo/operation/commands/list_collections/result.rb +63 -81
  54. data/lib/mongo/operation/commands/list_indexes.rb +27 -35
  55. data/lib/mongo/operation/commands/list_indexes/result.rb +67 -85
  56. data/lib/mongo/operation/commands/map_reduce.rb +29 -37
  57. data/lib/mongo/operation/commands/map_reduce/result.rb +85 -88
  58. data/lib/mongo/operation/commands/parallel_scan.rb +29 -33
  59. data/lib/mongo/operation/commands/parallel_scan/result.rb +34 -42
  60. data/lib/mongo/operation/commands/user_query.rb +40 -38
  61. data/lib/mongo/operation/commands/users_info.rb +24 -29
  62. data/lib/mongo/operation/commands/users_info/result.rb +13 -11
  63. data/lib/mongo/operation/object_id_generator.rb +36 -0
  64. data/lib/mongo/operation/result.rb +30 -0
  65. data/lib/mongo/operation/specifiable.rb +35 -1
  66. data/lib/mongo/operation/write/bulk/bulkable.rb +4 -3
  67. data/lib/mongo/operation/write/bulk/delete/result.rb +18 -25
  68. data/lib/mongo/operation/write/bulk/legacy_mergable.rb +2 -2
  69. data/lib/mongo/operation/write/command/delete.rb +3 -2
  70. data/lib/mongo/operation/write/command/insert.rb +4 -2
  71. data/lib/mongo/operation/write/command/update.rb +6 -3
  72. data/lib/mongo/operation/write/gle.rb +2 -1
  73. data/lib/mongo/operation/write/idable.rb +19 -2
  74. data/lib/mongo/options/mapper.rb +22 -0
  75. data/lib/mongo/protocol/bit_vector.rb +3 -3
  76. data/lib/mongo/protocol/delete.rb +15 -5
  77. data/lib/mongo/protocol/get_more.rb +10 -5
  78. data/lib/mongo/protocol/insert.rb +1 -6
  79. data/lib/mongo/protocol/kill_cursors.rb +14 -1
  80. data/lib/mongo/protocol/message.rb +32 -8
  81. data/lib/mongo/protocol/serializers.rb +15 -16
  82. data/lib/mongo/protocol/update.rb +35 -12
  83. data/lib/mongo/server/connectable.rb +3 -1
  84. data/lib/mongo/server/connection.rb +5 -5
  85. data/lib/mongo/server/description.rb +8 -2
  86. data/lib/mongo/server/description/features.rb +2 -1
  87. data/lib/mongo/server/monitor.rb +1 -12
  88. data/lib/mongo/server/monitor/connection.rb +30 -26
  89. data/lib/mongo/server_selector/selectable.rb +21 -4
  90. data/lib/mongo/uri.rb +2 -0
  91. data/lib/mongo/version.rb +1 -1
  92. data/lib/mongo/write_concern.rb +21 -6
  93. data/mongo.gemspec +1 -2
  94. data/spec/mongo/bulk_write/ordered_combiner_spec.rb +13 -0
  95. data/spec/mongo/bulk_write_spec.rb +58 -0
  96. data/spec/mongo/client_spec.rb +6 -4
  97. data/spec/mongo/collection/view/builder/find_command_spec.rb +167 -0
  98. data/spec/mongo/collection/view/builder/flags_spec.rb +106 -0
  99. data/spec/mongo/collection/view/builder/modifiers_spec.rb +210 -0
  100. data/spec/mongo/collection/view/builder/op_query_spec.rb +154 -0
  101. data/spec/mongo/collection/view/explainable_spec.rb +1 -2
  102. data/spec/mongo/collection/view/immutable_spec.rb +3 -52
  103. data/spec/mongo/collection/view/map_reduce_spec.rb +12 -12
  104. data/spec/mongo/collection/view/readable_spec.rb +86 -80
  105. data/spec/mongo/collection/view_spec.rb +109 -703
  106. data/spec/mongo/collection_spec.rb +594 -11
  107. data/spec/mongo/command_monitoring_spec.rb +40 -27
  108. data/spec/mongo/cursor/builder/get_more_command_spec.rb +160 -0
  109. data/spec/mongo/cursor/builder/op_get_more_spec.rb +52 -0
  110. data/spec/mongo/cursor_spec.rb +10 -60
  111. data/spec/mongo/database_spec.rb +24 -3
  112. data/spec/mongo/dbref_spec.rb +4 -4
  113. data/spec/mongo/grid/file/chunk_spec.rb +1 -1
  114. data/spec/mongo/grid/fs_bucket_spec.rb +3 -3
  115. data/spec/mongo/index/view_spec.rb +41 -0
  116. data/spec/mongo/operation/{aggregate → commands/aggregate}/result_spec.rb +1 -1
  117. data/spec/mongo/operation/commands/aggregate_spec.rb +1 -1
  118. data/spec/mongo/operation/commands/collections_info_spec.rb +1 -1
  119. data/spec/mongo/operation/commands/command_spec.rb +1 -1
  120. data/spec/mongo/operation/commands/indexes_spec.rb +1 -1
  121. data/spec/mongo/operation/commands/map_reduce_spec.rb +1 -1
  122. data/spec/mongo/operation/write/command/delete_spec.rb +25 -0
  123. data/spec/mongo/operation/write/command/insert_spec.rb +25 -0
  124. data/spec/mongo/operation/write/command/update_spec.rb +25 -0
  125. data/spec/mongo/protocol/delete_spec.rb +4 -4
  126. data/spec/mongo/protocol/get_more_spec.rb +4 -4
  127. data/spec/mongo/protocol/insert_spec.rb +3 -3
  128. data/spec/mongo/protocol/kill_cursors_spec.rb +3 -3
  129. data/spec/mongo/protocol/query_spec.rb +7 -7
  130. data/spec/mongo/protocol/update_spec.rb +5 -5
  131. data/spec/mongo/server/description/features_spec.rb +25 -0
  132. data/spec/mongo/write_concern_spec.rb +126 -0
  133. data/spec/spec_helper.rb +9 -19
  134. data/spec/support/command_monitoring.rb +8 -0
  135. data/spec/support/command_monitoring/find.yml +53 -4
  136. data/spec/support/matchers.rb +1 -1
  137. data/spec/support/shared/protocol.rb +5 -5
  138. data/spec/support/travis.rb +1 -1
  139. metadata +43 -10
  140. metadata.gz.sig +0 -0
@@ -149,8 +149,8 @@ module Mongo
149
149
  # @return [ Hash ] The result of the command execution.
150
150
  def command(operation, opts = {})
151
151
  preference = ServerSelector.get(client.options.merge(opts[:read])) if opts[:read]
152
- server = preference ? preference.select_server(cluster) : cluster.next_primary
153
- Operation::Command.new({
152
+ server = preference ? preference.select_server(cluster, false) : cluster.next_primary(false)
153
+ Operation::Commands::Command.new({
154
154
  :selector => operation,
155
155
  :db_name => name,
156
156
  :options => { :limit => -1 },
@@ -50,11 +50,15 @@ module Mongo
50
50
  # @since 2.0.0
51
51
  def collection_names(options = {})
52
52
  @batch_size = options[:batch_size]
53
- server = next_primary
53
+ server = next_primary(false)
54
54
  @limit = -1 if server.features.list_collections_enabled?
55
55
  collections_info(server).collect do |info|
56
- server.features.list_collections_enabled? ?
57
- info[Database::NAME] : info[Database::NAME].sub("#{@database.name}.", '')
56
+ if server.features.list_collections_enabled?
57
+ info[Database::NAME]
58
+ else
59
+ (info[Database::NAME] &&
60
+ info[Database::NAME].sub("#{@database.name}.", ''))
61
+ end
58
62
  end
59
63
  end
60
64
 
@@ -67,7 +71,7 @@ module Mongo
67
71
  #
68
72
  # @since 2.0.5
69
73
  def list_collections
70
- collections_info(next_primary)
74
+ collections_info(next_primary(false))
71
75
  end
72
76
 
73
77
  # Create the new database view.
@@ -103,7 +107,7 @@ module Mongo
103
107
  end
104
108
 
105
109
  def initial_query_op
106
- Operation::CollectionsInfo.new(collections_info_spec)
110
+ Operation::Commands::CollectionsInfo.new(collections_info_spec)
107
111
  end
108
112
 
109
113
  def send_initial_query(server)
@@ -84,8 +84,8 @@ module Mongo
84
84
  # @return [ String ] The raw BSON.
85
85
  #
86
86
  # @since 2.1.0
87
- def to_bson(encoded = ''.force_encoding(BSON::BINARY))
88
- as_json.to_bson(encoded)
87
+ def to_bson(buffer = BSON::ByteBuffer.new)
88
+ as_json.to_bson(buffer)
89
89
  end
90
90
 
91
91
  module ClassMethods
@@ -99,7 +99,7 @@ module Mongo
99
99
  # @see http://bsonspec.org/#/specification
100
100
  #
101
101
  # @since 2.0.0
102
- def from_bson(bson)
102
+ def from_bson(buffer)
103
103
  decoded = super
104
104
  if ref = decoded[COLLECTION]
105
105
  decoded = DBRef.new(ref, decoded[ID], decoded[DATABASE])
@@ -84,6 +84,7 @@ require 'mongo/error/invalid_server_preference'
84
84
  require 'mongo/error/invalid_signature'
85
85
  require 'mongo/error/invalid_update_document'
86
86
  require 'mongo/error/invalid_uri'
87
+ require 'mongo/error/invalid_write_concern'
87
88
  require 'mongo/error/max_bson_size'
88
89
  require 'mongo/error/max_message_size'
89
90
  require 'mongo/error/multi_index_drop'
@@ -0,0 +1,35 @@
1
+ # Copyright (C) 2014-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 Error
17
+
18
+ # Raised when an invalid write concern is provided.
19
+ #
20
+ # @since 2.2.0
21
+ class InvalidWriteConcern < Error
22
+
23
+ # Instantiate the new exception.
24
+ #
25
+ # @example Instantiate the exception.
26
+ # Mongo::Error::InvalidWriteConcern.new
27
+ #
28
+ # @since 2.2.0
29
+ def initialize
30
+ super('Invalid write concern options. If w is an Integer, it must be greater than or equal to 0. ' +
31
+ 'If w is 0, it cannot be combined with a true value for fsync or j (journal).')
32
+ end
33
+ end
34
+ end
35
+ end
@@ -133,8 +133,8 @@ module Mongo
133
133
  # @return [ String ] The raw BSON data.
134
134
  #
135
135
  # @since 2.0.0
136
- def to_bson(encoded = ''.force_encoding(BSON::BINARY))
137
- document.to_bson(encoded)
136
+ def to_bson(buffer = BSON::ByteBuffer.new)
137
+ document.to_bson(buffer)
138
138
  end
139
139
 
140
140
  class << self
@@ -56,6 +56,7 @@ module Mongo
56
56
  :max => :max,
57
57
  :min => :min,
58
58
  :name => :name,
59
+ :partial_filter_expression => :partialFilterExpression,
59
60
  :sparse => :sparse,
60
61
  :sphere_version => :'2dsphereIndexVersion',
61
62
  :storage_engine => :storageEngine,
@@ -114,6 +115,8 @@ module Mongo
114
115
  # a geo index.
115
116
  # @option options [ Integer ] :min (nil) Specify the min latitude and longitude for
116
117
  # a geo index.
118
+ # @option options [ Hash ] :partial_filter_expression Specify a filter for a partial
119
+ # index.
117
120
  #
118
121
  # @note Note that the options listed may be subset of those available.
119
122
  # See the MongoDB documentation for a full list of supported options by server version.
@@ -179,7 +182,7 @@ module Mongo
179
182
  #
180
183
  # @since 2.0.0
181
184
  def each(&block)
182
- server = next_primary
185
+ server = next_primary(false)
183
186
  cursor = Cursor.new(self, send_initial_query(server), server).to_enum
184
187
  cursor.each do |doc|
185
188
  yield doc
@@ -229,7 +232,7 @@ module Mongo
229
232
  end
230
233
 
231
234
  def initial_query_op
232
- Operation::Indexes.new(indexes_spec)
235
+ Operation::Commands::Indexes.new(indexes_spec)
233
236
  end
234
237
 
235
238
  def limit; -1; end
@@ -16,6 +16,7 @@ require 'mongo/operation/result'
16
16
  require 'mongo/operation/executable'
17
17
  require 'mongo/operation/specifiable'
18
18
  require 'mongo/operation/limited'
19
+ require 'mongo/operation/object_id_generator'
19
20
  require 'mongo/operation/read_preference'
20
21
  require 'mongo/operation/read'
21
22
  require 'mongo/operation/write'
@@ -13,6 +13,8 @@
13
13
  # limitations under the License.
14
14
 
15
15
  require 'mongo/operation/commands/command'
16
+ require 'mongo/operation/commands/find'
17
+ require 'mongo/operation/commands/get_more'
16
18
  require 'mongo/operation/commands/parallel_scan'
17
19
  require 'mongo/operation/commands/aggregate'
18
20
  require 'mongo/operation/commands/map_reduce'
@@ -12,59 +12,53 @@
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/aggregate/result'
16
-
17
15
  module Mongo
18
16
  module Operation
17
+ module Commands
19
18
 
20
- # A MongoDB aggregate operation.
21
- #
22
- # @note An aggregate operation can behave like a read and return a
23
- # result set, or can behave like a write operation and
24
- # output results to a user-specified collection.
25
- #
26
- # @example Create the aggregate operation.
27
- # Aggregate.new({
28
- # :selector => {
29
- # :aggregate => 'test_coll', :pipeline => [{ '$out' => 'test-out' }]
30
- # },
31
- # :db_name => 'test_db'
32
- # })
33
- #
34
- # Initialization:
35
- # param [ Hash ] spec The specifications for the operation.
36
- #
37
- # option spec :selector [ Hash ] The aggregate selector.
38
- # option spec :db_name [ String ] The name of the database on which
39
- # the operation should be executed.
40
- # option spec :options [ Hash ] Options for the aggregate command.
41
- #
42
- # @since 2.0.0
43
- class Aggregate
44
- include Specifiable
45
- include Limited
46
- include Executable
47
- include ReadPreference
19
+ # A MongoDB aggregate operation.
20
+ #
21
+ # @note An aggregate operation can behave like a read and return a
22
+ # result set, or can behave like a write operation and
23
+ # output results to a user-specified collection.
24
+ #
25
+ # @example Create the aggregate operation.
26
+ # Aggregate.new({
27
+ # :selector => {
28
+ # :aggregate => 'test_coll', :pipeline => [{ '$out' => 'test-out' }]
29
+ # },
30
+ # :db_name => 'test_db'
31
+ # })
32
+ #
33
+ # Initialization:
34
+ # param [ Hash ] spec The specifications for the operation.
35
+ #
36
+ # option spec :selector [ Hash ] The aggregate selector.
37
+ # option spec :db_name [ String ] The name of the database on which
38
+ # the operation should be executed.
39
+ # option spec :options [ Hash ] Options for the aggregate command.
40
+ #
41
+ # @since 2.0.0
42
+ class Aggregate < Command
48
43
 
49
- private
50
-
51
- def query_coll
52
- Database::COMMAND
53
- end
44
+ private
54
45
 
55
- def filter_selector(context)
56
- return selector if context.features.write_command_enabled?
57
- selector.reject{ |option, value| option.to_s == 'cursor' }
58
- end
46
+ def filter_selector(context)
47
+ return selector if context.features.write_command_enabled?
48
+ selector.reject{ |option, value| option.to_s == 'cursor' }
49
+ end
59
50
 
60
- def update_selector(context)
61
- if context.mongos? && read_pref = read.to_mongos
62
- sel = selector[:$query] ? filter_selector(context) : { :$query => filter_selector(context) }
63
- sel.merge(:$readPreference => read_pref)
64
- else
65
- filter_selector(context)
51
+ def update_selector(context)
52
+ if context.mongos? && read_pref = read.to_mongos
53
+ sel = selector[:$query] ? filter_selector(context) : { :$query => filter_selector(context) }
54
+ sel.merge(:$readPreference => read_pref)
55
+ else
56
+ filter_selector(context)
57
+ end
66
58
  end
67
59
  end
68
60
  end
69
61
  end
70
62
  end
63
+
64
+ require 'mongo/operation/commands/aggregate/result'
@@ -14,88 +14,74 @@
14
14
 
15
15
  module Mongo
16
16
  module Operation
17
- class Aggregate
17
+ module Commands
18
18
 
19
- # Defines custom behaviour of results in an aggregation context.
19
+ # Aggregate result wrapper.
20
20
  #
21
21
  # @since 2.0.0
22
- class Result < Operation::Result
22
+ class Aggregate
23
23
 
24
- # The field name for the cursor document in an aggregation.
24
+ # Defines custom behaviour of results in an aggregation context.
25
25
  #
26
26
  # @since 2.0.0
27
- CURSOR = 'cursor'.freeze
27
+ class Result < Operation::Result
28
28
 
29
- # The cursor id field in the cursor document.
30
- #
31
- # @since 2.0.0
32
- CURSOR_ID = 'id'.freeze
33
-
34
- # The field name for the aggregation explain information.
35
- #
36
- # @since 2.0.5
37
- EXPLAIN = 'stages'.freeze
38
-
39
- # The legacy field name for the aggregation explain information.
40
- #
41
- # @since 2.0.5
42
- EXPLAIN_LEGACY = 'serverPipeline'.freeze
29
+ # The field name for the aggregation explain information.
30
+ #
31
+ # @since 2.0.5
32
+ EXPLAIN = 'stages'.freeze
43
33
 
44
- # The field name for the first batch of a cursor.
45
- #
46
- # @since 2.0.0
47
- FIRST_BATCH = 'firstBatch'.freeze
48
-
49
- # The field name for a result without a cursor.
50
- #
51
- # @since 2.0.0
52
- RESULT = 'result'.freeze
34
+ # The legacy field name for the aggregation explain information.
35
+ #
36
+ # @since 2.0.5
37
+ EXPLAIN_LEGACY = 'serverPipeline'.freeze
53
38
 
54
- # Get the cursor id for the result.
55
- #
56
- # @example Get the cursor id.
57
- # result.cursor_id
58
- #
59
- # @note Even though the wire protocol has a cursor_id field for all
60
- # messages of type reply, it is always zero when using the
61
- # aggregation framework and must be retrieved from the cursor
62
- # document itself. Wahnsinn!
63
- #
64
- # @return [ Integer ] The cursor id.
65
- #
66
- # @since 2.0.0
67
- def cursor_id
68
- cursor_document ? cursor_document[CURSOR_ID] : super
69
- end
39
+ # Get the cursor id for the result.
40
+ #
41
+ # @example Get the cursor id.
42
+ # result.cursor_id
43
+ #
44
+ # @note Even though the wire protocol has a cursor_id field for all
45
+ # messages of type reply, it is always zero when using the
46
+ # aggregation framework and must be retrieved from the cursor
47
+ # document itself. Wahnsinn!
48
+ #
49
+ # @return [ Integer ] The cursor id.
50
+ #
51
+ # @since 2.0.0
52
+ def cursor_id
53
+ cursor_document ? cursor_document[CURSOR_ID] : super
54
+ end
70
55
 
71
- # Get the documents for the aggregation result. This is either the
72
- # first document's 'result' field, or if a cursor option was selected
73
- # it is the 'firstBatch' field in the 'cursor' field of the first
74
- # document returned.
75
- #
76
- # @example Get the documents.
77
- # result.documents
78
- #
79
- # @return [ Array<BSON::Document> ] The documents.
80
- #
81
- # @since 2.0.0
82
- def documents
83
- reply.documents[0][RESULT] || explain_document ||
84
- cursor_document[FIRST_BATCH]
85
- end
56
+ # Get the documents for the aggregation result. This is either the
57
+ # first document's 'result' field, or if a cursor option was selected
58
+ # it is the 'firstBatch' field in the 'cursor' field of the first
59
+ # document returned.
60
+ #
61
+ # @example Get the documents.
62
+ # result.documents
63
+ #
64
+ # @return [ Array<BSON::Document> ] The documents.
65
+ #
66
+ # @since 2.0.0
67
+ def documents
68
+ reply.documents[0][RESULT] || explain_document ||
69
+ cursor_document[FIRST_BATCH]
70
+ end
86
71
 
87
- private
72
+ private
88
73
 
89
- def explain_document
90
- first_document[EXPLAIN] || first_document[EXPLAIN_LEGACY]
91
- end
74
+ def explain_document
75
+ first_document[EXPLAIN] || first_document[EXPLAIN_LEGACY]
76
+ end
92
77
 
93
- def cursor_document
94
- @cursor_document ||= reply.documents[0][CURSOR]
95
- end
78
+ def cursor_document
79
+ @cursor_document ||= reply.documents[0][CURSOR]
80
+ end
96
81
 
97
- def first_document
98
- @first_document ||= reply.documents[0]
82
+ def first_document
83
+ @first_document ||= reply.documents[0]
84
+ end
99
85
  end
100
86
  end
101
87
  end
@@ -16,52 +16,54 @@ require 'mongo/operation/commands/collections_info/result'
16
16
 
17
17
  module Mongo
18
18
  module Operation
19
+ module Commands
19
20
 
20
- # A MongoDB operation to get a list of collection names in a database.
21
- #
22
- # @example Create the collection names operation.
23
- # Read::CollectionNames.new(:db_name => 'test-db')
24
- #
25
- # Initialization:
26
- # param [ Hash ] spec The specifications for the collection names operation.
27
- #
28
- # option spec :db_name [ String ] The name of the database whose collection
29
- # names is requested.
30
- # option spec :options [ Hash ] Options for the operation.
31
- #
32
- # @since 2.0.0
33
- class CollectionsInfo
34
- include Specifiable
35
- include ReadPreference
36
- include Executable
37
-
38
- # Execute the operation.
39
- # The context gets a connection on which the operation
40
- # is sent in the block.
21
+ # A MongoDB operation to get a list of collection names in a database.
22
+ #
23
+ # @example Create the collection names operation.
24
+ # Read::CollectionNames.new(:db_name => 'test-db')
41
25
  #
42
- # @param [ Mongo::Server::Context ] context The context for this operation.
26
+ # Initialization:
27
+ # param [ Hash ] spec The specifications for the collection names operation.
43
28
  #
44
- # @return [ Result ] The operation response, if there is one.
29
+ # option spec :db_name [ String ] The name of the database whose collection
30
+ # names is requested.
31
+ # option spec :options [ Hash ] Options for the operation.
45
32
  #
46
33
  # @since 2.0.0
47
- def execute(context)
48
- if context.features.list_collections_enabled?
49
- ListCollections.new(spec).execute(context)
50
- else
51
- context.with_connection do |connection|
52
- Result.new(connection.dispatch([ message(context) ])).validate!
34
+ class CollectionsInfo
35
+ include Specifiable
36
+ include ReadPreference
37
+ include Executable
38
+
39
+ # Execute the operation.
40
+ # The context gets a connection on which the operation
41
+ # is sent in the block.
42
+ #
43
+ # @param [ Mongo::Server::Context ] context The context for this operation.
44
+ #
45
+ # @return [ Result ] The operation response, if there is one.
46
+ #
47
+ # @since 2.0.0
48
+ def execute(context)
49
+ if context.features.list_collections_enabled?
50
+ ListCollections.new(spec).execute(context)
51
+ else
52
+ context.with_connection do |connection|
53
+ Result.new(connection.dispatch([ message(context) ])).validate!
54
+ end
53
55
  end
54
56
  end
55
- end
56
57
 
57
- private
58
+ private
58
59
 
59
- def selector
60
- { :name => { '$not' => /system\.|\$/ } }
61
- end
60
+ def selector
61
+ { :name => { '$not' => /system\.|\$/ } }
62
+ end
62
63
 
63
- def query_coll
64
- Database::NAMESPACES
64
+ def query_coll
65
+ Database::NAMESPACES
66
+ end
65
67
  end
66
68
  end
67
69
  end