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
@@ -0,0 +1,83 @@
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 Collection
17
+ class View
18
+ module Builder
19
+
20
+ # Builds a legacy OP_QUERY specification from options.
21
+ #
22
+ # @since 2.2.0
23
+ class OpQuery
24
+ extend Forwardable
25
+
26
+ def_delegators :@view, :cluster, :collection, :database, :filter, :options, :read
27
+
28
+ # @return [ BSON::Document ] modifiers The server modifiers.
29
+ attr_reader :modifiers
30
+
31
+ # Create the new legacy query builder.
32
+ #
33
+ # @example Create the query builder.
34
+ # QueryBuilder.new(view)
35
+ #
36
+ # @param [ Collection::View ] view The collection view.
37
+ #
38
+ # @since 2.2.2
39
+ def initialize(view)
40
+ @view = view
41
+ @modifiers = Modifiers.map_server_modifiers(options)
42
+ end
43
+
44
+ def specification
45
+ {
46
+ :selector => requires_special_filter? ? special_filter : filter,
47
+ :read => read,
48
+ :options => query_options,
49
+ :db_name => database.name,
50
+ :coll_name => collection.name
51
+ }
52
+ end
53
+
54
+ private
55
+
56
+ def query_options
57
+ BSON::Document.new(
58
+ project: options[:projection],
59
+ skip: options[:skip],
60
+ limit: options[:limit],
61
+ flags: Flags.map_flags(options),
62
+ batch_size: options[:batch_size]
63
+ )
64
+ end
65
+
66
+ def requires_special_filter?
67
+ !modifiers.empty? || cluster.sharded?
68
+ end
69
+
70
+ def read_pref_formatted
71
+ @read_formatted ||= read.to_mongos
72
+ end
73
+
74
+ def special_filter
75
+ sel = BSON::Document.new(:$query => filter).merge!(modifiers)
76
+ sel[:$readPreference] = read_pref_formatted unless read_pref_formatted.nil?
77
+ sel
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -21,6 +21,21 @@ module Mongo
21
21
  # @since 2.0.0
22
22
  module Explainable
23
23
 
24
+ # The query planner verbosity constant.
25
+ #
26
+ # @since 2.2.0
27
+ QUERY_PLANNER = 'queryPlanner'.freeze
28
+
29
+ # The execution stats verbosity constant.
30
+ #
31
+ # @since 2.2.0
32
+ EXECUTION_STATS = 'executionStats'.freeze
33
+
34
+ # The all plans execution verbosity constant.
35
+ #
36
+ # @since 2.2.0
37
+ ALL_PLANS_EXECUTION = 'allPlansExecution'.freeze
38
+
24
39
  # Get the explain plan for the query.
25
40
  #
26
41
  # @example Get the explain plan for the query.
@@ -15,6 +15,10 @@
15
15
  module Mongo
16
16
  class Collection
17
17
  class View
18
+
19
+ # Defines behaviour around views being configurable and immutable.
20
+ #
21
+ # @since 2.0.0
18
22
  module Immutable
19
23
 
20
24
  # @return [ Hash ] options The additional query options.
@@ -24,18 +28,7 @@ module Mongo
24
28
 
25
29
  def configure(field, value)
26
30
  return options[field] if value.nil?
27
- new(options.merge(field => value, :modifiers => @modifiers))
28
- end
29
-
30
- def configure_modifier(field, value)
31
- return @modifiers[Readable::SPECIAL_FIELDS[field]] if value.nil?
32
- new(options.merge(:modifiers => @modifiers.merge(Readable::SPECIAL_FIELDS[field] => value)))
33
- end
34
-
35
- def configure_flag(flag)
36
- new(options.dup).tap do |view|
37
- view.send(:flags).push(flag)
38
- end
31
+ new(options.merge(field => value))
39
32
  end
40
33
  end
41
34
  end
@@ -37,7 +37,7 @@ module Mongo
37
37
  def each
38
38
  @cursor = nil
39
39
  read_with_retry do
40
- server = read.select_server(cluster)
40
+ server = read.select_server(cluster, false)
41
41
  result = send_initial_query(server)
42
42
  @cursor = Cursor.new(view, result, server)
43
43
  end
@@ -54,7 +54,29 @@ module Mongo
54
54
  #
55
55
  # @since 2.1.0
56
56
  def close_query
57
- @cursor.send(:kill_cursors) if @cursor
57
+ @cursor.send(:kill_cursors) if @cursor && !@cursor.closed?
58
+ end
59
+
60
+ private
61
+
62
+ def initial_query_op(server)
63
+ if server.features.find_command_enabled?
64
+ initial_command_op
65
+ else
66
+ Operation::Read::Query.new(Builder::OpQuery.new(self).specification)
67
+ end
68
+ end
69
+
70
+ def initial_command_op
71
+ if explained?
72
+ Operation::Commands::Command.new(Builder::FindCommand.new(self).explain_specification)
73
+ else
74
+ Operation::Commands::Find.new(Builder::FindCommand.new(self).specification)
75
+ end
76
+ end
77
+
78
+ def send_initial_query(server)
79
+ initial_query_op(server).execute(server.context)
58
80
  end
59
81
  end
60
82
  end
@@ -67,7 +67,7 @@ module Mongo
67
67
  def each
68
68
  @cursor = nil
69
69
  write_with_retry do
70
- server = read.select_server(cluster)
70
+ server = read.select_server(cluster, false)
71
71
  result = send_initial_query(server)
72
72
  @cursor = Cursor.new(view, result, server)
73
73
  end
@@ -107,7 +107,7 @@ module Mongo
107
107
  @view = view
108
108
  @map = map.freeze
109
109
  @reduce = reduce.freeze
110
- @options = options.dup
110
+ @options = options.freeze
111
111
  end
112
112
 
113
113
  # Set or get the jsMode flag for the operation.
@@ -122,7 +122,7 @@ module Mongo
122
122
  #
123
123
  # @since 2.0.0
124
124
  def js_mode(value = nil)
125
- configure(:jsMode, value)
125
+ configure(:js_mode, value)
126
126
  end
127
127
 
128
128
  # Set or get the output location for the operation.
@@ -187,21 +187,7 @@ module Mongo
187
187
  end
188
188
 
189
189
  def map_reduce_spec
190
- {
191
- :db_name => database.name,
192
- :read => read,
193
- :selector => {
194
- :mapreduce => collection.name,
195
- :map => map,
196
- :reduce => reduce,
197
- :query => view.modifiers[:$query] || view.selector,
198
- :out => { inline: 1 }
199
- }.merge(options).merge(view_options)
200
- }
201
- end
202
-
203
- def view_options
204
- view.sort ? view.options.merge(:sort => view.sort) : view.options
190
+ Builder::MapReduce.new(map, reduce, view, options).specification
205
191
  end
206
192
 
207
193
  def new(options)
@@ -209,7 +195,7 @@ module Mongo
209
195
  end
210
196
 
211
197
  def initial_query_op
212
- Operation::MapReduce.new(map_reduce_spec)
198
+ Operation::Commands::MapReduce.new(map_reduce_spec)
213
199
  end
214
200
 
215
201
  def valid_server?(server)
@@ -223,25 +209,30 @@ module Mongo
223
209
  def send_initial_query(server)
224
210
  unless valid_server?(server)
225
211
  log_warn(REROUTE)
226
- server = cluster.next_primary
212
+ server = cluster.next_primary(false)
227
213
  end
228
214
  result = initial_query_op.execute(server.context)
229
215
  inline? ? result : send_fetch_query(server)
230
216
  end
231
217
 
232
218
  def fetch_query_spec
233
- { :selector => {},
234
- :options => {},
235
- :db_name => database.name,
236
- :coll_name => out.respond_to?(:keys) ? out.values.first : out }
219
+ Builder::MapReduce.new(map, reduce, view, options).query_specification
237
220
  end
238
221
 
239
- def fetch_query_op
240
- Operation::Read::Query.new(fetch_query_spec)
222
+ def find_command_spec
223
+ Builder::MapReduce.new(map, reduce, view, options).command_specification
224
+ end
225
+
226
+ def fetch_query_op(server)
227
+ if server.features.find_command_enabled?
228
+ Operation::Commands::Find.new(find_command_spec)
229
+ else
230
+ Operation::Read::Query.new(fetch_query_spec)
231
+ end
241
232
  end
242
233
 
243
234
  def send_fetch_query(server)
244
- fetch_query_op.execute(server.context)
235
+ fetch_query_op(server).execute(server.context)
245
236
  end
246
237
  end
247
238
  end
@@ -21,33 +21,15 @@ module Mongo
21
21
  # @since 2.0.0
22
22
  module Readable
23
23
 
24
- # Special fields and their option names for the query selector.
24
+ # The query modifier constant.
25
25
  #
26
- # @since 2.0.0
27
- SPECIAL_FIELDS = {
28
- :sort => :$orderby,
29
- :hint => :$hint,
30
- :comment => :$comment,
31
- :snapshot => :$snapshot,
32
- :max_scan => :$maxScan,
33
- :max_value => :$max,
34
- :min_value => :$min,
35
- :max_time_ms => :$maxTimeMS,
36
- :return_key => :$returnKey,
37
- :show_disk_loc => :$showDiskLoc,
38
- :explain => :$explain
39
- }.freeze
40
-
41
- # Options to cursor flags mapping.
26
+ # @since 2.2.0
27
+ QUERY = '$query'.freeze
28
+
29
+ # The modifiers option constant.
42
30
  #
43
- # @since 2.1.0
44
- CURSOR_FLAGS_MAP = {
45
- :allow_partial_results => [ :partial ],
46
- :oplog_replay => [ :oplog_replay ],
47
- :no_cursor_timeout => [ :no_cursor_timeout ],
48
- :tailable => [ :tailable_cursor ],
49
- :tailable_await => [ :await_data, :tailable_cursor]
50
- }.freeze
31
+ # @since 2.2.0
32
+ MODIFIERS = 'modifiers'.freeze
51
33
 
52
34
  # Execute an aggregation on the collection view.
53
35
  #
@@ -75,7 +57,19 @@ module Mongo
75
57
  #
76
58
  # @since 2.0.0
77
59
  def allow_partial_results
78
- configure_flag(:partial)
60
+ configure(:allow_partial_results, true)
61
+ end
62
+
63
+ # Tell the query's cursor to stay open and wait for data.
64
+ #
65
+ # @example Await data on the cursor.
66
+ # view.await_data
67
+ #
68
+ # @return [ View ] The new view.
69
+ #
70
+ # @since 2.0.0
71
+ def await_data
72
+ configure(:await_data, true)
79
73
  end
80
74
 
81
75
  # The number of documents returned in each batch of results from MongoDB.
@@ -110,7 +104,7 @@ module Mongo
110
104
  #
111
105
  # @since 2.0.0
112
106
  def comment(comment = nil)
113
- configure_modifier(:comment, comment)
107
+ configure(:comment, comment)
114
108
  end
115
109
 
116
110
  # Get a count of matching documents in the collection.
@@ -132,11 +126,12 @@ module Mongo
132
126
  #
133
127
  # @since 2.0.0
134
128
  def count(options = {})
135
- cmd = { :count => collection.name, :query => selector }
129
+ cmd = { :count => collection.name, :query => filter }
136
130
  cmd[:skip] = options[:skip] if options[:skip]
137
131
  cmd[:hint] = options[:hint] if options[:hint]
138
132
  cmd[:limit] = options[:limit] if options[:limit]
139
133
  cmd[:maxTimeMS] = options[:max_time_ms] if options[:max_time_ms]
134
+ cmd[:readConcern] = collection.read_concern if collection.read_concern
140
135
  read_with_retry do
141
136
  database.command(cmd, options).n.to_i
142
137
  end
@@ -160,8 +155,9 @@ module Mongo
160
155
  def distinct(field_name, options={})
161
156
  cmd = { :distinct => collection.name,
162
157
  :key => field_name.to_s,
163
- :query => selector }
158
+ :query => filter }
164
159
  cmd[:maxTimeMS] = options[:max_time_ms] if options[:max_time_ms]
160
+ cmd[:readConcern] = collection.read_concern if collection.read_concern
165
161
  read_with_retry do
166
162
  database.command(cmd, options).first['values']
167
163
  end
@@ -178,7 +174,7 @@ module Mongo
178
174
  #
179
175
  # @since 2.0.0
180
176
  def hint(hint = nil)
181
- configure_modifier(:hint, hint)
177
+ configure(:hint, hint)
182
178
  end
183
179
 
184
180
  # The max number of docs to return from the query.
@@ -222,7 +218,7 @@ module Mongo
222
218
  #
223
219
  # @since 2.0.0
224
220
  def max_scan(value = nil)
225
- configure_modifier(:max_scan, value)
221
+ configure(:max_scan, value)
226
222
  end
227
223
 
228
224
  # Set the maximum value to search.
@@ -236,7 +232,7 @@ module Mongo
236
232
  #
237
233
  # @since 2.1.0
238
234
  def max_value(value = nil)
239
- configure_modifier(:max_value, value)
235
+ configure(:max_value, value)
240
236
  end
241
237
 
242
238
  # Set the minimum value to search.
@@ -250,7 +246,7 @@ module Mongo
250
246
  #
251
247
  # @since 2.1.0
252
248
  def min_value(value = nil)
253
- configure_modifier(:min_value, value)
249
+ configure(:min_value, value)
254
250
  end
255
251
 
256
252
  # The server normally times out idle cursors after an inactivity period
@@ -263,7 +259,7 @@ module Mongo
263
259
  #
264
260
  # @since 2.0.0
265
261
  def no_cursor_timeout
266
- configure_flag(:no_cursor_timeout)
262
+ configure(:no_cursor_timeout, true)
267
263
  end
268
264
 
269
265
  # The fields to include or exclude from each doc in the result set.
@@ -313,7 +309,7 @@ module Mongo
313
309
  #
314
310
  # @since 2.1.0
315
311
  def return_key(value = nil)
316
- configure_modifier(:return_key, value)
312
+ configure(:return_key, value)
317
313
  end
318
314
 
319
315
  # Set whether the disk location should be shown for each document.
@@ -328,8 +324,9 @@ module Mongo
328
324
  #
329
325
  # @since 2.0.0
330
326
  def show_disk_loc(value = nil)
331
- configure_modifier(:show_disk_loc, value)
327
+ configure(:show_disk_loc, value)
332
328
  end
329
+ alias :show_record_id :show_disk_loc
333
330
 
334
331
  # The number of docs to skip before returning results.
335
332
  #
@@ -358,7 +355,7 @@ module Mongo
358
355
  #
359
356
  # @since 2.0.0
360
357
  def snapshot(value = nil)
361
- configure_modifier(:snapshot, value)
358
+ configure(:snapshot, value)
362
359
  end
363
360
 
364
361
  # The key and direction pairs by which the result set will be sorted.
@@ -373,7 +370,7 @@ module Mongo
373
370
  #
374
371
  # @since 2.0.0
375
372
  def sort(spec = nil)
376
- configure_modifier(:sort, spec)
373
+ configure(:sort, spec)
377
374
  end
378
375
 
379
376
  # “meta” operators that let you modify the output or behavior of a query.
@@ -387,8 +384,23 @@ module Mongo
387
384
  #
388
385
  # @since 2.1.0
389
386
  def modifiers(doc = nil)
390
- return @modifiers if doc.nil?
391
- new(options.merge(:modifiers => doc))
387
+ return Builder::Modifiers.map_server_modifiers(options) if doc.nil?
388
+ new(options.merge(Builder::Modifiers.map_driver_options(doc)))
389
+ end
390
+
391
+ # A cumulative time limit in milliseconds for processing get more operations
392
+ # on a cursor.
393
+ #
394
+ # @example Set the max await time ms value.
395
+ # view.max_await_time_ms(500)
396
+ #
397
+ # @param [ Integer ] max The max time in milliseconds.
398
+ #
399
+ # @return [ Integer, View ] Either the max await time ms value or a new +View+.
400
+ #
401
+ # @since 2.1.0
402
+ def max_await_time_ms(max = nil)
403
+ configure(:max_await_time_ms, max)
392
404
  end
393
405
 
394
406
  # A cumulative time limit in milliseconds for processing operations on a cursor.
@@ -402,7 +414,7 @@ module Mongo
402
414
  #
403
415
  # @since 2.1.0
404
416
  def max_time_ms(max = nil)
405
- configure_modifier(:max_time_ms, max)
417
+ configure(:max_time_ms, max)
406
418
  end
407
419
 
408
420
  private
@@ -411,85 +423,31 @@ module Mongo
411
423
  options[:read] || read_preference
412
424
  end
413
425
 
414
- def flags
415
- @flags ||= CURSOR_FLAGS_MAP.each.reduce([]) do |flags, (key, value)|
416
- if options[key] || (options[:cursor_type] && options[:cursor_type] == key)
417
- flags.push(*value)
418
- end
419
- flags
420
- end
421
- end
422
-
423
426
  def parallel_scan(cursor_count)
424
- server = read.select_server(cluster)
425
- Operation::ParallelScan.new(
427
+ server = read.select_server(cluster, false)
428
+ Operation::Commands::ParallelScan.new(
426
429
  :coll_name => collection.name,
427
430
  :db_name => database.name,
428
- :cursor_count => cursor_count
431
+ :cursor_count => cursor_count,
432
+ :read_concern => collection.read_concern
429
433
  ).execute(server.context).cursor_ids.map do |cursor_id|
430
- result = Operation::Read::GetMore.new({ :to_return => 0,
431
- :cursor_id => cursor_id,
432
- :db_name => database.name,
433
- :coll_name => collection.name
434
- }).execute(server.context)
434
+ result = if server.features.find_command_enabled?
435
+ Operation::Commands::GetMore.new({
436
+ :selector => { :getMore => cursor_id, :collection => collection.name },
437
+ :db_name => database.name
438
+ }).execute(server.context)
439
+ else
440
+ Operation::Read::GetMore.new({
441
+ :to_return => 0,
442
+ :cursor_id => cursor_id,
443
+ :db_name => database.name,
444
+ :coll_name => collection.name
445
+ }).execute(server.context)
446
+ end
435
447
  Cursor.new(self, result, server)
436
448
  end
437
449
  end
438
450
 
439
- def setup(sel, opts)
440
- setup_options(opts)
441
- setup_selector(sel)
442
- end
443
-
444
- def setup_options(opts)
445
- @options = opts ? opts.dup : {}
446
- @modifiers = @options[:modifiers] ? @options.delete(:modifiers).dup : BSON::Document.new
447
- @options.keys.each { |k| @modifiers.merge!(SPECIAL_FIELDS[k] => @options.delete(k)) if SPECIAL_FIELDS[k] }
448
- @options.freeze
449
- end
450
-
451
- def setup_selector(sel)
452
- @selector = sel ? sel.dup : {}
453
- if @selector[:$query] || @selector['$query']
454
- @selector.keys.each { |k| @modifiers.merge!(k => @selector.delete(k)) if k[0] == '$' }
455
- end
456
- @modifiers.freeze
457
- @selector.freeze
458
- end
459
-
460
- def query_options
461
- {
462
- :project => projection,
463
- :skip => skip,
464
- :limit => limit,
465
- :flags => flags,
466
- :batch_size => batch_size
467
- }
468
- end
469
-
470
- def requires_special_selector?
471
- !modifiers.empty? || cluster.sharded?
472
- end
473
-
474
- def query_spec
475
- sel = requires_special_selector? ? special_selector : selector
476
- { :selector => sel,
477
- :read => read,
478
- :options => query_options,
479
- :db_name => database.name,
480
- :coll_name => collection.name }
481
- end
482
-
483
- def read_pref_formatted
484
- @read_formatted ||= read.to_mongos
485
- end
486
-
487
- def special_selector
488
- sel = BSON::Document.new(:$query => selector).merge!(modifiers)
489
- sel[:$readPreference] = read_pref_formatted unless read_pref_formatted.nil?
490
- sel
491
- end
492
-
493
451
  def validate_doc!(doc)
494
452
  raise Error::InvalidDocument.new unless doc.respond_to?(:keys)
495
453
  end