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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5848eb885418bc7cba6b6a44761b1b47f4bbcb7d
4
- data.tar.gz: fa960cc01b750a11b49a30a64cc602a6b665898e
3
+ metadata.gz: dcc9c2c71373a6cf0c7ecc20e34dc665a3609113
4
+ data.tar.gz: b0586f936825521d4d1b720aaab115094c754b52
5
5
  SHA512:
6
- metadata.gz: 5b6809a0802bba0bc3bd58d45dff14a15f6bddf4194deaa4063fadebf27bcb1a3af451c28f1076d5094ab18a65522b5571ca62bd5e2ff3baaf3d583e3962ec1c
7
- data.tar.gz: da274d6b705a440c81d7fb9f09a413ef3a200ca1af858c1eb0b82db1a4ffd95edba29d07872e031440c5822bcac4114cabf40b3b3b32d1af349e4d80452fdb28
6
+ metadata.gz: 4bd095acd88b753375c7b32441645a7f79bd6e79fa66c4b49d1d16f98a17a3ebb88628132d863dee8a49132b0ad06cd540fc329b37d3250e1793ecf0ce0fbb55
7
+ data.tar.gz: 8081fad549d197c92f9b573694b32a1813030fcde279e98ab117dd9d4b601b5bb2139a720c218b03fadd3315a8a9f391066f7ad96c99f194ce1cf186b6a56673
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- MongoDB Ruby Driver [![Build Status][travis-img]][travis-url] [![Code Climate][codeclimate-img]][codeclimate-url] [![Coverage Status][coveralls-img]][coveralls-url] [![Gem Version][rubygems-img]][rubygems-url]
1
+ MongoDB Ruby Driver [![Build Status][travis-img]][travis-url] [![Code Climate][codeclimate-img]][codeclimate-url] [![Gem Version][rubygems-img]][rubygems-url]
2
2
  -----
3
3
  The officially supported Ruby driver for [MongoDB](http://www.mongodb.org).
4
4
 
@@ -40,6 +40,15 @@ When reporting an issue, please keep in mind that all information in JIRA for al
40
40
  * Provide any sensitive data or server logs.
41
41
  * Report potential security issues publicly (see 'Security Issues').
42
42
 
43
+ Running Tests
44
+ -----
45
+
46
+ The driver uses RSpec as it's primary testing tool. To run all tests simple run `rspec`.
47
+
48
+ To run a test at a specific location (where `42` is the line number), use:
49
+
50
+ rspec path/to/spec.rb:42
51
+
43
52
  Security Issues
44
53
  -----
45
54
 
@@ -74,5 +83,3 @@ License
74
83
  [travis-url]: http://travis-ci.org/mongodb/mongo-ruby-driver?branch=master
75
84
  [codeclimate-img]: https://codeclimate.com/github/mongodb/mongo-ruby-driver.png?branch=master
76
85
  [codeclimate-url]: https://codeclimate.com/github/mongodb/mongo-ruby-driver?branch=master
77
- [coveralls-img]: https://coveralls.io/repos/mongodb/mongo-ruby-driver/badge.png?branch=master
78
- [coveralls-url]: https://coveralls.io/r/mongodb/mongo-ruby-driver?branch=master
data/Rakefile CHANGED
@@ -19,13 +19,7 @@ RSpec::Core::RakeTask.new(:spec)
19
19
  task :default => :spec
20
20
 
21
21
  namespace :spec do
22
- if RUBY_VERSION > '1.9' && RUBY_VERSION < '2.2'
23
- require 'coveralls/rake/task'
24
- Coveralls::RakeTask.new
25
- task :ci => [:spec, 'coveralls:push']
26
- else
27
- task :ci => [:spec]
28
- end
22
+ task :ci => [:spec]
29
23
  end
30
24
 
31
25
  task :release => :spec do
Binary file
@@ -112,7 +112,7 @@ module Mongo
112
112
  private
113
113
 
114
114
  def user_query(name)
115
- Operation::UserQuery.new(
115
+ Operation::Commands::UserQuery.new(
116
116
  user_name: name,
117
117
  db_name: database.name
118
118
  ).execute(next_primary.context)
@@ -37,6 +37,8 @@ module Mongo
37
37
  # Delegate various methods to the collection.
38
38
  def_delegators :@collection, :database, :cluster, :next_primary
39
39
 
40
+ def_delegators :database, :client
41
+
40
42
  # Execute the bulk write operation.
41
43
  #
42
44
  # @example Execute the bulk write.
@@ -131,7 +133,10 @@ module Mongo
131
133
  :coll_name => collection.name,
132
134
  :write_concern => write_concern,
133
135
  :ordered => ordered?,
134
- :operation_id => operation_id
136
+ :operation_id => operation_id,
137
+ :bypass_document_validation => !!options[:bypass_document_validation],
138
+ :options => options,
139
+ :id_generator => client.options[:id_generator]
135
140
  }
136
141
  end
137
142
 
@@ -143,6 +148,7 @@ module Mongo
143
148
  combiner.combine!(send(name, values, server, operation_id), values.size)
144
149
  end
145
150
  rescue Error::MaxBSONSize, Error::MaxMessageSize => e
151
+ raise e if values.size <= 1
146
152
  split_execute(name, values, server, operation_id, combiner)
147
153
  end
148
154
  end
@@ -33,33 +33,35 @@ module Mongo
33
33
  # @since 2.1.2
34
34
  VALID_OPTIONS = [
35
35
  :auth_mech,
36
+ :auth_mech_properties,
36
37
  :auth_source,
37
38
  :connect,
39
+ :connect_timeout,
38
40
  :database,
39
- :auth_mech_properties,
40
41
  :heartbeat_frequency,
42
+ :id_generator,
41
43
  :local_threshold,
42
- :server_selection_timeout,
43
- :password,
44
+ :logger,
44
45
  :max_pool_size,
46
+ :max_read_retries,
45
47
  :min_pool_size,
46
- :wait_queue_timeout,
47
- :connect_timeout,
48
+ :monitoring,
49
+ :password,
48
50
  :read,
49
- :roles,
51
+ :read_retry_interval,
50
52
  :replica_set,
53
+ :server_selection_timeout,
54
+ :socket_timeout,
51
55
  :ssl,
56
+ :ssl_ca_cert,
52
57
  :ssl_cert,
53
58
  :ssl_key,
54
59
  :ssl_key_pass_phrase,
55
60
  :ssl_verify,
56
- :ssl_ca_cert,
57
- :socket_timeout,
61
+ :truncate_logs,
58
62
  :user,
59
- :write,
60
- :monitoring,
61
- :logger,
62
- :truncate_logs
63
+ :wait_queue_timeout,
64
+ :write
63
65
  ].freeze
64
66
 
65
67
  # @return [ Mongo::Cluster ] cluster The cluster of servers for the client.
@@ -160,8 +162,6 @@ module Mongo
160
162
  # and local_threshold.
161
163
  # :mode can be one of :secondary, :secondary_preferred, :primary,
162
164
  # :primary_preferred, :nearest.
163
- # @option options [ Array<Hash, String> ] :roles The list of roles for the
164
- # user.
165
165
  # @option options [ Symbol ] :replica_set The name of the replica set to
166
166
  # connect to. Servers not in this replica set will be ignored.
167
167
  # @option options [ true, false ] :ssl Whether to use SSL.
@@ -180,7 +180,7 @@ module Mongo
180
180
  # execute operations on a socket.
181
181
  # @option options [ String ] :user The user name.
182
182
  # @option options [ Hash ] :write The write concern options. Can be :w =>
183
- # Integer, :fsync => Boolean, :j => Boolean.
183
+ # Integer|String, :fsync => Boolean, :j => Boolean.
184
184
  # @option options [ true, false ] :monitoring Initializes a client without
185
185
  # any default monitoring if false is provided.
186
186
  # @option options [ Logger ] :logger A custom logger if desired.
@@ -190,6 +190,8 @@ module Mongo
190
190
  # retries on mongos query failures.
191
191
  # @option options [ Float ] :read_retry_interval The interval, in seconds,
192
192
  # in which reads on a mongos are retried.
193
+ # @option options [ Object ] :id_generator A custom object to generate ids
194
+ # for documents. Must respond to #generate.
193
195
  #
194
196
  # @since 2.0.0
195
197
  def initialize(addresses_or_uri, options = Options::Redacted.new)
@@ -131,11 +131,13 @@ module Mongo
131
131
  # @example Get the next primary server.
132
132
  # cluster.next_primary
133
133
  #
134
+ # @param [ true, false ] ping Whether to ping the server before selection.
135
+ #
134
136
  # @return [ Mongo::Server ] A primary server.
135
137
  #
136
138
  # @since 2.0.0
137
- def next_primary
138
- ServerSelector.get(ServerSelector::PRIMARY.merge(options)).select_server(self)
139
+ def next_primary(ping = true)
140
+ ServerSelector.get(ServerSelector::PRIMARY.merge(options)).select_server(self, ping)
139
141
  end
140
142
 
141
143
  # Elect a primary server from the description that has just changed to a
@@ -56,7 +56,7 @@ module Mongo
56
56
  # Options that can be updated on a new Collection instance via the #with method.
57
57
  #
58
58
  # @since 2.1.0
59
- CHANGEABLE_OPTIONS = [ :read, :write ]
59
+ CHANGEABLE_OPTIONS = [ :read, :read_concern, :write ].freeze
60
60
 
61
61
  # Check if a collection is equal to another object. Will check the name and
62
62
  # the database for equality.
@@ -91,6 +91,18 @@ module Mongo
91
91
  @options = options.freeze
92
92
  end
93
93
 
94
+ # Get the read concern for this collection instance.
95
+ #
96
+ # @example Get the read concern.
97
+ # collection.read_concern
98
+ #
99
+ # @return [ Hash ] The read concern.
100
+ #
101
+ # @since 2.2.0
102
+ def read_concern
103
+ @read_concern ||= options[:read_concern]
104
+ end
105
+
94
106
  # Get the read preference on this collection.
95
107
  #
96
108
  # @example Get the read preference.
@@ -235,6 +247,8 @@ module Mongo
235
247
  # aggregation to run.
236
248
  # @option options [ true, false ] :use_cursor Indicates whether the command will request that the server
237
249
  # provide results using a cursor.
250
+ # @option options [ true, false ] :bypass_document_validation Whether or
251
+ # not to skip document level validation.
238
252
  #
239
253
  # @return [ Aggregation ] The aggregation object.
240
254
  #
@@ -326,7 +340,9 @@ module Mongo
326
340
  :db_name => database.name,
327
341
  :coll_name => name,
328
342
  :write_concern => write_concern,
329
- :options => options
343
+ :bypass_document_validation => !!options[:bypass_document_validation],
344
+ :options => options,
345
+ :id_generator => client.options[:id_generator]
330
346
  ).execute(next_primary.context)
331
347
  end
332
348
  end
@@ -359,6 +375,8 @@ module Mongo
359
375
  # should be executed in order.
360
376
  # @option options [ Hash ] :write_concern The write concern options.
361
377
  # Can be :w => Integer, :fsync => Boolean, :j => Boolean.
378
+ # @option options [ true, false ] :bypass_document_validation Whether or
379
+ # not to skip document level validation.
362
380
  #
363
381
  # @return [ BulkWrite::Result ] The result of the operation.
364
382
  #
@@ -424,6 +442,8 @@ module Mongo
424
442
  #
425
443
  # @option options [ true, false ] :upsert Whether to upsert if the
426
444
  # document doesn't exist.
445
+ # @option options [ true, false ] :bypass_document_validation Whether or
446
+ # not to skip document level validation.
427
447
  #
428
448
  # @return [ Result ] The response from the database.
429
449
  #
@@ -443,6 +463,8 @@ module Mongo
443
463
  #
444
464
  # @option options [ true, false ] :upsert Whether to upsert if the
445
465
  # document doesn't exist.
466
+ # @option options [ true, false ] :bypass_document_validation Whether or
467
+ # not to skip document level validation.
446
468
  #
447
469
  # @return [ Result ] The response from the database.
448
470
  #
@@ -462,6 +484,8 @@ module Mongo
462
484
  #
463
485
  # @option options [ true, false ] :upsert Whether to upsert if the
464
486
  # document doesn't exist.
487
+ # @option options [ true, false ] :bypass_document_validation Whether or
488
+ # not to skip document level validation.
465
489
  #
466
490
  # @return [ Result ] The response from the database.
467
491
  #
@@ -484,6 +508,8 @@ module Mongo
484
508
  # @option options [ Hash ] :projection The fields to include or exclude in the returned doc.
485
509
  # @option options [ Hash ] :sort The key and direction pairs by which the result set
486
510
  # will be sorted.
511
+ # @option options [ Hash ] :write_concern The write concern options.
512
+ # Defaults to the collection's write concern.
487
513
  #
488
514
  # @return [ BSON::Document, nil ] The document, if found.
489
515
  #
@@ -512,6 +538,10 @@ module Mongo
512
538
  # will be sorted.
513
539
  # @option options [ Symbol ] :return_document Either :before or :after.
514
540
  # @option options [ true, false ] :upsert Whether to upsert if the document doesn't exist.
541
+ # @option options [ true, false ] :bypass_document_validation Whether or
542
+ # not to skip document level validation.
543
+ # @option options [ Hash ] :write_concern The write concern options.
544
+ # Defaults to the collection's write concern.
515
545
  #
516
546
  # @return [ BSON::Document ] The document.
517
547
  #
@@ -540,6 +570,10 @@ module Mongo
540
570
  # will be sorted.
541
571
  # @option options [ Symbol ] :return_document Either :before or :after.
542
572
  # @option options [ true, false ] :upsert Whether to upsert if the document doesn't exist.
573
+ # @option options [ true, false ] :bypass_document_validation Whether or
574
+ # not to skip document level validation.
575
+ # @option options [ Hash ] :write_concern The write concern options.
576
+ # Defaults to the collection's write concern.
543
577
  #
544
578
  # @return [ BSON::Document ] The document.
545
579
  #
@@ -12,6 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ require 'mongo/collection/view/builder'
15
16
  require 'mongo/collection/view/immutable'
16
17
  require 'mongo/collection/view/iterable'
17
18
  require 'mongo/collection/view/explainable'
@@ -48,10 +49,11 @@ module Mongo
48
49
  include Explainable
49
50
  include Writable
50
51
 
51
- # @return [ View ] The +View+ to query.
52
+ # @return [ Collection ] The +Collection+ to query.
52
53
  attr_reader :collection
53
- # @return [ Hash ] The query selector.
54
- attr_reader :selector
54
+
55
+ # @return [ Hash ] The query filter.
56
+ attr_reader :filter
55
57
 
56
58
  # Delegate necessary operations to the collection.
57
59
  def_delegators :collection, :client, :cluster, :database, :read_preference, :write_concern
@@ -59,25 +61,27 @@ module Mongo
59
61
  # Delegate to the cluster for the next primary.
60
62
  def_delegators :cluster, :next_primary
61
63
 
64
+ alias :selector :filter
65
+
62
66
  # Compare two +View+ objects.
63
67
  #
64
68
  # @example Compare the view with another object.
65
69
  # view == other
66
70
  #
67
- # @return [ true, false ] Equal if collection, selector, and options of two
71
+ # @return [ true, false ] Equal if collection, filter, and options of two
68
72
  # +View+ match.
69
73
  #
70
74
  # @since 2.0.0
71
75
  def ==(other)
72
76
  return false unless other.is_a?(View)
73
77
  collection == other.collection &&
74
- selector == other.selector &&
78
+ filter == other.filter &&
75
79
  options == other.options
76
80
  end
77
81
  alias_method :eql?, :==
78
82
 
79
83
  # A hash value for the +View+ composed of the collection namespace,
80
- # hash of the options and hash of the selector.
84
+ # hash of the options and hash of the filter.
81
85
  #
82
86
  # @example Get the hash value.
83
87
  # view.hash
@@ -86,7 +90,7 @@ module Mongo
86
90
  #
87
91
  # @since 2.0.0
88
92
  def hash
89
- [ collection.namespace, options.hash, selector.hash ].hash
93
+ [ collection.namespace, options.hash, filter.hash ].hash
90
94
  end
91
95
 
92
96
  # Creates a new +View+.
@@ -101,7 +105,7 @@ module Mongo
101
105
  # View.new(collection, {:name => 'Emily'}, :read => :secondary_preferred)
102
106
  #
103
107
  # @param [ Collection ] collection The +Collection+ to query.
104
- # @param [ Hash ] selector The query selector.
108
+ # @param [ Hash ] filter The query filter.
105
109
  # @param [ Hash ] options The additional query options.
106
110
  #
107
111
  # @option options :comment [ String ] Associate a comment with the query.
@@ -125,10 +129,10 @@ module Mongo
125
129
  # results.
126
130
  #
127
131
  # @since 2.0.0
128
- def initialize(collection, selector = {}, options = {})
129
- validate_doc!(selector)
132
+ def initialize(collection, filter = {}, options = {})
133
+ validate_doc!(filter)
130
134
  @collection = collection
131
- setup(selector, options)
135
+ parse_parameters!(BSON::Document.new(filter.freeze), BSON::Document.new(options.freeze))
132
136
  end
133
137
 
134
138
  # Get a human-readable string representation of +View+.
@@ -140,8 +144,8 @@ module Mongo
140
144
  #
141
145
  # @since 2.0.0
142
146
  def inspect
143
- "#<Mongo::Collection::View:0x#{object_id} namespace='#{collection.namespace}" +
144
- " @selector=#{selector.inspect} @options=#{options.inspect}>"
147
+ "#<Mongo::Collection::View:0x#{object_id} namespace='#{collection.namespace}'" +
148
+ " @filter=#{filter.to_s} @options=#{options.to_s}>"
145
149
  end
146
150
 
147
151
  private
@@ -149,19 +153,18 @@ module Mongo
149
153
  def initialize_copy(other)
150
154
  @collection = other.collection
151
155
  @options = other.options.dup
152
- @selector = other.selector.dup
156
+ @filter = other.filter.dup
153
157
  end
154
158
 
155
- def initial_query_op
156
- Operation::Read::Query.new(query_spec)
159
+ def parse_parameters!(filter, options)
160
+ query = filter.delete(QUERY)
161
+ modifiers = (filter || {}).merge(options.delete(MODIFIERS) || {})
162
+ @filter = query || filter
163
+ @options = Builder::Modifiers.map_driver_options(modifiers).merge!(options)
157
164
  end
158
165
 
159
166
  def new(options)
160
- View.new(collection, selector, options)
161
- end
162
-
163
- def send_initial_query(server)
164
- initial_query_op.execute(server.context)
167
+ View.new(collection, filter, options)
165
168
  end
166
169
 
167
170
  def view; self; end
@@ -39,15 +39,6 @@ module Mongo
39
39
  # Delegate necessary operations to the collection.
40
40
  def_delegators :collection, :database
41
41
 
42
- # Options mapping for an aggregation.
43
- #
44
- # @since 2.1.0
45
- OPTIONS_MAP = {
46
- :allow_disk_use => :allowDiskUse,
47
- :max_time_ms => :maxTimeMS,
48
- :explain => :explain
49
- }.freeze
50
-
51
42
  # The reroute message.
52
43
  #
53
44
  # @since 2.1.0
@@ -65,7 +56,7 @@ module Mongo
65
56
  #
66
57
  # @since 2.0.0
67
58
  def allow_disk_use(value = nil)
68
- configure(__method__, value)
59
+ configure(:allow_disk_use, value)
69
60
  end
70
61
 
71
62
  # Initialize the aggregation for the provided collection view, pipeline
@@ -94,41 +85,13 @@ module Mongo
94
85
  #
95
86
  # @since 2.0.0
96
87
  def explain
97
- self.class.new(view, pipeline, options.merge(explain_options)).first
88
+ self.class.new(view, pipeline, options.merge(explain: true)).first
98
89
  end
99
90
 
100
91
  private
101
92
 
102
93
  def aggregate_spec
103
- { :db_name => database.name,
104
- :read => read,
105
- :selector => {
106
- :aggregate => collection.name,
107
- :pipeline => pipeline,
108
- :cursor => cursor,
109
- }.merge!(agg_options)
110
- }
111
- end
112
-
113
- def agg_options
114
- @agg_options ||= options.each.reduce({}) do |opts, (key, value)|
115
- OPTIONS_MAP[key] ? opts.merge!(OPTIONS_MAP[key] => value) : opts
116
- end
117
- end
118
-
119
- def cursor
120
- if options[:use_cursor] == true || options[:use_cursor].nil?
121
- batch_size_doc
122
- end
123
- end
124
-
125
- def batch_size_doc
126
- (value = options[:batch_size] || view.batch_size) ?
127
- { :batchSize => value } : {}
128
- end
129
-
130
- def explain_options
131
- { :explain => true }
94
+ Builder::Aggregation.new(pipeline, view, options).specification
132
95
  end
133
96
 
134
97
  def new(options)
@@ -136,7 +99,7 @@ module Mongo
136
99
  end
137
100
 
138
101
  def initial_query_op
139
- Operation::Aggregate.new(aggregate_spec)
102
+ Operation::Commands::Aggregate.new(aggregate_spec)
140
103
  end
141
104
 
142
105
  def valid_server?(server)
@@ -150,7 +113,7 @@ module Mongo
150
113
  def send_initial_query(server)
151
114
  unless valid_server?(server)
152
115
  log_warn(REROUTE)
153
- server = cluster.next_primary
116
+ server = cluster.next_primary(false)
154
117
  end
155
118
  initial_query_op.execute(server.context)
156
119
  end