mongo 2.3.1 → 2.4.0.rc0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -3
  4. data/lib/mongo/bulk_write.rb +8 -7
  5. data/lib/mongo/bulk_write/combineable.rb +4 -0
  6. data/lib/mongo/bulk_write/transformable.rb +17 -5
  7. data/lib/mongo/bulk_write/validatable.rb +1 -0
  8. data/lib/mongo/client.rb +3 -0
  9. data/lib/mongo/cluster.rb +8 -0
  10. data/lib/mongo/cluster/app_metadata.rb +135 -0
  11. data/lib/mongo/collection.rb +42 -10
  12. data/lib/mongo/collection/view.rb +15 -1
  13. data/lib/mongo/collection/view/aggregation.rb +5 -0
  14. data/lib/mongo/collection/view/builder/aggregation.rb +13 -3
  15. data/lib/mongo/collection/view/builder/find_command.rb +7 -21
  16. data/lib/mongo/collection/view/builder/map_reduce.rb +22 -5
  17. data/lib/mongo/collection/view/iterable.rb +1 -0
  18. data/lib/mongo/collection/view/map_reduce.rb +5 -0
  19. data/lib/mongo/collection/view/readable.rb +35 -14
  20. data/lib/mongo/collection/view/writable.rb +54 -23
  21. data/lib/mongo/cursor/builder/get_more_command.rb +2 -3
  22. data/lib/mongo/database.rb +10 -2
  23. data/lib/mongo/error.rb +2 -0
  24. data/lib/mongo/error/invalid_application_name.rb +38 -0
  25. data/lib/mongo/error/invalid_server_preference.rb +24 -3
  26. data/lib/mongo/error/unsupported_collation.rb +51 -0
  27. data/lib/mongo/index/view.rb +28 -15
  28. data/lib/mongo/operation.rb +6 -0
  29. data/lib/mongo/operation/commands.rb +3 -0
  30. data/lib/mongo/operation/commands/aggregate.rb +10 -10
  31. data/lib/mongo/operation/commands/create.rb +45 -0
  32. data/lib/mongo/operation/commands/drop.rb +45 -0
  33. data/lib/mongo/operation/commands/drop_database.rb +45 -0
  34. data/lib/mongo/operation/commands/map_reduce.rb +12 -1
  35. data/lib/mongo/operation/commands/parallel_scan.rb +1 -0
  36. data/lib/mongo/operation/read_preference.rb +9 -9
  37. data/lib/mongo/operation/specifiable.rb +34 -0
  38. data/lib/mongo/operation/takes_write_concern.rb +35 -0
  39. data/lib/mongo/operation/write/bulk/bulkable.rb +1 -1
  40. data/lib/mongo/operation/write/command/create_index.rb +6 -0
  41. data/lib/mongo/operation/write/command/drop_index.rb +6 -0
  42. data/lib/mongo/operation/write/command/insert.rb +1 -1
  43. data/lib/mongo/operation/write/command/update.rb +1 -0
  44. data/lib/mongo/operation/write/command/writable.rb +2 -2
  45. data/lib/mongo/operation/write/create_index.rb +2 -2
  46. data/lib/mongo/operation/write/create_user.rb +1 -1
  47. data/lib/mongo/operation/write/delete.rb +5 -1
  48. data/lib/mongo/operation/write/gle.rb +1 -1
  49. data/lib/mongo/operation/write/insert.rb +2 -2
  50. data/lib/mongo/operation/write/remove_user.rb +1 -1
  51. data/lib/mongo/operation/write/update.rb +5 -1
  52. data/lib/mongo/operation/write/update_user.rb +1 -1
  53. data/lib/mongo/operation/write/write_command_enabled.rb +10 -2
  54. data/lib/mongo/protocol/insert.rb +1 -2
  55. data/lib/mongo/protocol/query.rb +3 -7
  56. data/lib/mongo/server.rb +8 -3
  57. data/lib/mongo/server/connection.rb +17 -11
  58. data/lib/mongo/server/description.rb +22 -0
  59. data/lib/mongo/server/description/features.rb +2 -0
  60. data/lib/mongo/server/monitor.rb +5 -0
  61. data/lib/mongo/server/monitor/connection.rb +11 -0
  62. data/lib/mongo/server_selector/nearest.rb +9 -6
  63. data/lib/mongo/server_selector/primary.rb +4 -0
  64. data/lib/mongo/server_selector/primary_preferred.rb +7 -1
  65. data/lib/mongo/server_selector/secondary.rb +5 -0
  66. data/lib/mongo/server_selector/secondary_preferred.rb +7 -2
  67. data/lib/mongo/server_selector/selectable.rb +57 -10
  68. data/lib/mongo/socket/ssl.rb +1 -0
  69. data/lib/mongo/uri.rb +4 -0
  70. data/lib/mongo/version.rb +1 -1
  71. data/lib/mongo/write_concern.rb +1 -0
  72. data/mongo.gemspec +1 -1
  73. data/spec/mongo/auth/cr_spec.rb +7 -1
  74. data/spec/mongo/auth/ldap_spec.rb +7 -1
  75. data/spec/mongo/auth/scram_spec.rb +7 -1
  76. data/spec/mongo/auth/x509_spec.rb +7 -1
  77. data/spec/mongo/bulk_write_spec.rb +598 -5
  78. data/spec/mongo/client_spec.rb +47 -1
  79. data/spec/mongo/cluster/app_metadata_spec.rb +104 -0
  80. data/spec/mongo/cluster/topology/replica_set_spec.rb +14 -8
  81. data/spec/mongo/cluster/topology/sharded_spec.rb +9 -3
  82. data/spec/mongo/cluster/topology/single_spec.rb +10 -4
  83. data/spec/mongo/cluster_spec.rb +29 -0
  84. data/spec/mongo/collection/view/aggregation_spec.rb +139 -0
  85. data/spec/mongo/collection/view/builder/find_command_spec.rb +6 -243
  86. data/spec/mongo/collection/view/map_reduce_spec.rb +104 -0
  87. data/spec/mongo/collection/view/readable_spec.rb +83 -0
  88. data/spec/mongo/collection/view/writable_spec.rb +447 -1
  89. data/spec/mongo/collection/view_spec.rb +57 -0
  90. data/spec/mongo/collection_spec.rb +926 -101
  91. data/spec/mongo/crud_spec.rb +4 -5
  92. data/spec/mongo/database_spec.rb +99 -1
  93. data/spec/mongo/index/view_spec.rb +360 -31
  94. data/spec/mongo/max_staleness_spec.rb +108 -0
  95. data/spec/mongo/operation/read_preference_spec.rb +8 -8
  96. data/spec/mongo/operation/write/command/delete_spec.rb +1 -1
  97. data/spec/mongo/operation/write/command/insert_spec.rb +1 -1
  98. data/spec/mongo/operation/write/command/update_spec.rb +1 -1
  99. data/spec/mongo/server/connection_pool_spec.rb +3 -1
  100. data/spec/mongo/server/connection_spec.rb +17 -7
  101. data/spec/mongo/server/description/features_spec.rb +50 -0
  102. data/spec/mongo/server/description_spec.rb +9 -3
  103. data/spec/mongo/server_selection_spec.rb +5 -3
  104. data/spec/mongo/server_selector/nearest_spec.rb +73 -0
  105. data/spec/mongo/server_selector/primary_preferred_spec.rb +73 -0
  106. data/spec/mongo/server_selector/primary_spec.rb +36 -0
  107. data/spec/mongo/server_selector/secondary_preferred_spec.rb +73 -0
  108. data/spec/mongo/server_selector/secondary_spec.rb +73 -0
  109. data/spec/mongo/server_selector_spec.rb +53 -0
  110. data/spec/mongo/server_spec.rb +3 -1
  111. data/spec/mongo/uri_spec.rb +54 -0
  112. data/spec/mongo/write_concern_spec.rb +18 -0
  113. data/spec/spec_helper.rb +10 -0
  114. data/spec/support/authorization.rb +8 -1
  115. data/spec/support/crud.rb +15 -0
  116. data/spec/support/crud/read.rb +27 -19
  117. data/spec/support/crud/write.rb +28 -3
  118. data/spec/support/crud_tests/read/aggregate.yml +15 -3
  119. data/spec/support/crud_tests/read/count.yml +14 -3
  120. data/spec/support/crud_tests/read/distinct.yml +13 -1
  121. data/spec/support/crud_tests/read/find.yml +12 -2
  122. data/spec/support/crud_tests/write/deleteMany.yml +22 -1
  123. data/spec/support/crud_tests/write/deleteOne.yml +20 -1
  124. data/spec/support/crud_tests/write/findOneAndDelete.yml +27 -2
  125. data/spec/support/crud_tests/write/findOneAndReplace.yml +43 -14
  126. data/spec/support/crud_tests/write/findOneAndUpdate.yml +50 -8
  127. data/spec/support/crud_tests/write/replaceOne.yml +34 -10
  128. data/spec/support/crud_tests/write/updateMany.yml +42 -11
  129. data/spec/support/crud_tests/write/updateOne.yml +32 -7
  130. data/spec/support/max_staleness/ReplicaSetNoPrimary/DefaultNoMaxStaleness.yml +26 -0
  131. data/spec/support/max_staleness/ReplicaSetNoPrimary/Incompatible.yml +25 -0
  132. data/spec/support/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.yml +33 -0
  133. data/spec/support/max_staleness/ReplicaSetNoPrimary/Nearest.yml +33 -0
  134. data/spec/support/max_staleness/ReplicaSetNoPrimary/Nearest2.yml +33 -0
  135. data/spec/support/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.yml +27 -0
  136. data/spec/support/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.yml +36 -0
  137. data/spec/support/max_staleness/ReplicaSetNoPrimary/Secondary.yml +51 -0
  138. data/spec/support/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.yml +26 -0
  139. data/spec/support/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.yml +51 -0
  140. data/spec/support/max_staleness/ReplicaSetWithPrimary/DefaultNoMaxStaleness.yml +26 -0
  141. data/spec/support/max_staleness/ReplicaSetWithPrimary/Incompatible.yml +25 -0
  142. data/spec/support/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.yml +35 -0
  143. data/spec/support/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.yml +25 -0
  144. data/spec/support/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.yml +23 -0
  145. data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest.yml +33 -0
  146. data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest2.yml +33 -0
  147. data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest_tags.yml +36 -0
  148. data/spec/support/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.yml +27 -0
  149. data/spec/support/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.yml +27 -0
  150. data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.yml +26 -0
  151. data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.yml +59 -0
  152. data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.yml +43 -0
  153. data/spec/support/max_staleness/ReplicaSetWithPrimary/Secondary_tags.yml +59 -0
  154. data/spec/support/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.yml +43 -0
  155. data/spec/support/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness.yml +29 -0
  156. data/spec/support/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness2.yml +29 -0
  157. data/spec/support/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.yml +27 -0
  158. data/spec/support/max_staleness/Sharded/Incompatible.yml +25 -0
  159. data/spec/support/max_staleness/Sharded/SmallMaxStaleness.yml +20 -0
  160. data/spec/support/max_staleness/Single/Incompatible.yml +18 -0
  161. data/spec/support/max_staleness/Single/SmallMaxStaleness.yml +20 -0
  162. data/spec/support/server_selection.rb +25 -0
  163. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_multiple.yml +27 -0
  164. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_multi_tags.yml +31 -0
  165. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_multi_tags2.yml +31 -0
  166. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_multiple.yml +34 -0
  167. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred_tags.yml +28 -0
  168. data/spec/support/shared/server_selector.rb +4 -3
  169. metadata +91 -6
  170. metadata.gz.sig +0 -0
@@ -41,7 +41,18 @@ module Mongo
41
41
  # option spec :options [ Hash ] Options for the map reduce command.
42
42
  #
43
43
  # @since 2.0.0
44
- class MapReduce < Command; end
44
+ class MapReduce < Command
45
+ include TakesWriteConcern
46
+
47
+ private
48
+
49
+ def message(server)
50
+ sel = update_selector_for_read_pref(selector, server)
51
+ sel = update_selector_for_write_concern(sel, server)
52
+ opts = update_options_for_slave_ok(options, server)
53
+ Protocol::Query.new(db_name, query_coll, sel, opts)
54
+ end
55
+ end
45
56
  end
46
57
  end
47
58
  end
@@ -42,6 +42,7 @@ module Mongo
42
42
  def selector
43
43
  command = { :parallelCollectionScan => coll_name, :numCursors => cursor_count }
44
44
  command[:readConcern] = read_concern if read_concern
45
+ command[:maxTimeMS] = max_time_ms if max_time_ms
45
46
  command
46
47
  end
47
48
  end
@@ -28,12 +28,12 @@ module Mongo
28
28
 
29
29
  private
30
30
 
31
- def update_selector(server)
31
+ def update_selector_for_read_pref(sel, server)
32
32
  if server.mongos? && read_pref = read.to_mongos
33
- sel = selector[:$query] ? selector : { :$query => selector }
33
+ sel = sel[:$query] ? sel : { :$query => sel }
34
34
  sel.merge(:$readPreference => read_pref)
35
35
  else
36
- selector
36
+ sel
37
37
  end
38
38
  end
39
39
 
@@ -41,19 +41,19 @@ module Mongo
41
41
  (server.cluster.single? && !server.mongos?) || read.slave_ok?
42
42
  end
43
43
 
44
- def update_options(server)
44
+ def update_options_for_slave_ok(opts, server)
45
45
  if slave_ok?(server)
46
- options.dup.tap do |opts|
47
- (opts[:flags] ||= []) << SLAVE_OK
46
+ opts.dup.tap do |o|
47
+ (o[:flags] ||= []) << SLAVE_OK
48
48
  end
49
49
  else
50
- options
50
+ opts
51
51
  end
52
52
  end
53
53
 
54
54
  def message(server)
55
- sel = update_selector(server)
56
- opts = update_options(server)
55
+ sel = update_selector_for_read_pref(selector, server)
56
+ opts = update_options_for_slave_ok(options, server)
57
57
  Protocol::Query.new(db_name, query_coll, sel, opts)
58
58
  end
59
59
  end
@@ -91,6 +91,11 @@ module Mongo
91
91
  # @since 2.2.0
92
92
  READ_CONCERN = :read_concern.freeze
93
93
 
94
+ # The max time ms option.
95
+ #
96
+ # @since 2.2.5
97
+ MAX_TIME_MS = :max_time_ms.freeze
98
+
94
99
  # The field for a selector.
95
100
  #
96
101
  # @since 2.0.0
@@ -136,6 +141,11 @@ module Mongo
136
141
  # @since 2.2.0
137
142
  BYPASS_DOC_VALIDATION = :bypass_document_validation.freeze
138
143
 
144
+ # A collation to apply to the operation.
145
+ #
146
+ # @since 2.4.0
147
+ COLLATION = :collation.freeze
148
+
139
149
  # @return [ Hash ] spec The specification for the operation.
140
150
  attr_reader :spec
141
151
 
@@ -339,6 +349,18 @@ module Mongo
339
349
  spec[READ_CONCERN]
340
350
  end
341
351
 
352
+ # Get the max time ms value from the spec.
353
+ #
354
+ # @example Get the max time ms.
355
+ # specifiable.max_time_ms
356
+ #
357
+ # @return [ Hash ] The max time ms value.
358
+ #
359
+ # @since 2.2.5
360
+ def max_time_ms
361
+ spec[MAX_TIME_MS]
362
+ end
363
+
342
364
  # Whether or not to bypass document level validation.
343
365
  #
344
366
  # @example Get the bypass_document_validation option.
@@ -351,6 +373,18 @@ module Mongo
351
373
  spec[BYPASS_DOC_VALIDATION]
352
374
  end
353
375
 
376
+ # The collation to apply to the operation.
377
+ #
378
+ # @example Get the collation option.
379
+ # specifiable.collation.
380
+ #
381
+ # @return [ Hash ] The collation document.
382
+ #
383
+ # @since 2.4.0
384
+ def collation
385
+ spec[COLLATION]
386
+ end
387
+
354
388
  # The selector for from the specification.
355
389
  #
356
390
  # @example Get a selector specification.
@@ -0,0 +1,35 @@
1
+ # Copyright (C) 2014-2016 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
+ module Operation
17
+
18
+ # Adds behaviour for updating the selector for operations
19
+ # that may take a write concern.
20
+ #
21
+ # @since 2.4.0
22
+ module TakesWriteConcern
23
+
24
+ private
25
+
26
+ def update_selector_for_write_concern(sel, server)
27
+ if write_concern && server.features.collation_enabled?
28
+ sel.merge(writeConcern: write_concern.options)
29
+ else
30
+ sel
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -65,7 +65,7 @@ module Mongo
65
65
  def gle
66
66
  wc = write_concern || WriteConcern.get(WriteConcern::DEFAULT)
67
67
  gle_message = ( ordered? && wc.get_last_error.nil? ) ?
68
- Mongo::WriteConcern.get(Mongo::WriteConcern::DEFAULT).get_last_error :
68
+ WriteConcern.get(WriteConcern::DEFAULT).get_last_error :
69
69
  wc.get_last_error
70
70
  if gle_message
71
71
  Protocol::Query.new(
@@ -30,6 +30,7 @@ module Mongo
30
30
  class CreateIndex
31
31
  include Specifiable
32
32
  include Writable
33
+ include TakesWriteConcern
33
34
 
34
35
  private
35
36
 
@@ -41,6 +42,11 @@ module Mongo
41
42
  def selector
42
43
  { :createIndexes => coll_name, :indexes => indexes }
43
44
  end
45
+
46
+ def message(server)
47
+ sel = update_selector_for_write_concern(selector, server)
48
+ Protocol::Query.new(db_name, Database::COMMAND, sel, options)
49
+ end
44
50
  end
45
51
  end
46
52
  end
@@ -31,6 +31,7 @@ module Mongo
31
31
  class DropIndex
32
32
  include Specifiable
33
33
  include Writable
34
+ include TakesWriteConcern
34
35
 
35
36
  private
36
37
 
@@ -42,6 +43,11 @@ module Mongo
42
43
  def selector
43
44
  { :dropIndexes => coll_name, :index => index_name }
44
45
  end
46
+
47
+ def message(server)
48
+ sel = update_selector_for_write_concern(selector, server)
49
+ Protocol::Query.new(db_name, Database::COMMAND, sel, options)
50
+ end
45
51
  end
46
52
  end
47
53
  end
@@ -54,7 +54,7 @@ module Mongo
54
54
  # @return [ Mongo::Protocol::Query ] Wire protocol message.
55
55
  #
56
56
  # @since 2.2.5
57
- def message
57
+ def message(server)
58
58
  opts = options.merge(validating_keys: true)
59
59
  Protocol::Query.new(db_name, Database::COMMAND, selector, opts)
60
60
  end
@@ -52,6 +52,7 @@ module Mongo
52
52
  }.tap do |cmd|
53
53
  cmd.merge!(writeConcern: write_concern.options) if write_concern
54
54
  cmd.merge!(:bypassDocumentValidation => true) if bypass_document_validation
55
+ cmd.merge!(:collation => collation) if collation
55
56
  end
56
57
  end
57
58
  end
@@ -36,7 +36,7 @@ module Mongo
36
36
  # @since 2.0.0
37
37
  def execute(server)
38
38
  server.with_connection do |connection|
39
- connection.dispatch([ message ], operation_id)
39
+ connection.dispatch([ message(server) ], operation_id)
40
40
  end
41
41
  end
42
42
 
@@ -47,7 +47,7 @@ module Mongo
47
47
  # @return [ Mongo::Protocol::Query ] Wire protocol message.
48
48
  #
49
49
  # @since 2.0.0
50
- def message
50
+ def message(server)
51
51
  Protocol::Query.new(db_name, Database::COMMAND, selector, options)
52
52
  end
53
53
  end
@@ -58,8 +58,8 @@ module Mongo
58
58
  end
59
59
  end
60
60
 
61
- def message
62
- Protocol::Insert.new(db_name, Index::COLLECTION, index_documents, validating_keys: false)
61
+ def message(server)
62
+ Protocol::Insert.new(db_name, Index::COLLECTION, index_documents)
63
63
  end
64
64
  end
65
65
  end
@@ -40,7 +40,7 @@ module Mongo
40
40
  Command::CreateUser.new(spec)
41
41
  end
42
42
 
43
- def message
43
+ def message(server)
44
44
  user_spec = { user: user.name }.merge(user.spec)
45
45
  Protocol::Insert.new(db_name, Auth::User::COLLECTION, [ user_spec ])
46
46
  end
@@ -60,7 +60,11 @@ module Mongo
60
60
  Command::Delete.new(s)
61
61
  end
62
62
 
63
- def message
63
+ def has_collation?
64
+ delete[:collation]
65
+ end
66
+
67
+ def message(server)
64
68
  selector = delete[Operation::Q]
65
69
  opts = (delete[Operation::LIMIT] || 0) <= 0 ? {} : { :flags => [ :single_remove ] }
66
70
  Protocol::Delete.new(db_name, coll_name, selector, opts)
@@ -28,7 +28,7 @@ module Mongo
28
28
  server.with_connection do |connection|
29
29
  result_class = self.class.const_defined?(:LegacyResult, false) ? self.class::LegacyResult :
30
30
  self.class.const_defined?(:Result, false) ? self.class::Result : Result
31
- result_class.new(connection.dispatch([ message, gle ].compact)).validate!
31
+ result_class.new(connection.dispatch([ message(server), gle ].compact)).validate!
32
32
  end
33
33
  end
34
34
 
@@ -57,11 +57,11 @@ module Mongo
57
57
 
58
58
  def execute_message(server)
59
59
  server.with_connection do |connection|
60
- Result.new(connection.dispatch([ message, gle ].compact), @ids).validate!
60
+ Result.new(connection.dispatch([ message(server), gle ].compact), @ids).validate!
61
61
  end
62
62
  end
63
63
 
64
- def message
64
+ def message(server)
65
65
  opts = !!options[:continue_on_error] ? { :flags => [:continue_on_error] } : {}
66
66
  Protocol::Insert.new(db_name, coll_name, ensure_ids(documents), opts)
67
67
  end
@@ -39,7 +39,7 @@ module Mongo
39
39
  Command::RemoveUser.new(spec)
40
40
  end
41
41
 
42
- def message
42
+ def message(server)
43
43
  Protocol::Delete.new(db_name, Auth::User::COLLECTION, { user: user_name })
44
44
  end
45
45
  end
@@ -63,7 +63,11 @@ module Mongo
63
63
  Command::Update.new(s)
64
64
  end
65
65
 
66
- def message
66
+ def has_collation?
67
+ update[:collation]
68
+ end
69
+
70
+ def message(server)
67
71
  flags = []
68
72
  flags << :multi_update if update[Operation::MULTI]
69
73
  flags << :upsert if update[Operation::UPSERT]
@@ -40,7 +40,7 @@ module Mongo
40
40
  Command::UpdateUser.new(spec)
41
41
  end
42
42
 
43
- def message
43
+ def message(server)
44
44
  user_spec = { user: user.name }.merge(user.spec)
45
45
  Protocol::Update.new(db_name, Auth::User::COLLECTION, { user: user.name }, user_spec)
46
46
  end
@@ -34,8 +34,8 @@ module Mongo
34
34
  #
35
35
  # @since 2.1.0
36
36
  def execute(server)
37
- if !server.features.write_command_enabled? ||
38
- (write_concern && write_concern.get_last_error.nil?)
37
+ if !server.features.write_command_enabled? || unacknowledged_write?
38
+ raise Error::UnsupportedCollation.new(Error::UnsupportedCollation::UNACKNOWLEDGED_WRITES_MESSAGE) if has_collation?
39
39
  execute_message(server)
40
40
  else
41
41
  execute_write_command(server)
@@ -44,6 +44,14 @@ module Mongo
44
44
 
45
45
  private
46
46
 
47
+ def has_collation?
48
+ false
49
+ end
50
+
51
+ def unacknowledged_write?
52
+ write_concern && write_concern.get_last_error.nil?
53
+ end
54
+
47
55
  def execute_write_command(server)
48
56
  result_class = self.class.const_defined?(:Result, false) ? self.class::Result : Result
49
57
  result_class.new(write_command_op.execute(server)).validate!
@@ -54,7 +54,6 @@ module Mongo
54
54
  @documents = documents
55
55
  @flags = options[:flags] || []
56
56
  @upconverter = Upconverter.new(collection, documents, options)
57
- @options = options
58
57
  end
59
58
 
60
59
  # Return the event payload for monitoring.
@@ -77,7 +76,7 @@ module Mongo
77
76
  private
78
77
 
79
78
  def validating_keys?
80
- @options.fetch(:validating_keys, true)
79
+ true
81
80
  end
82
81
 
83
82
  attr_reader :upconverter
@@ -252,7 +252,7 @@ module Mongo
252
252
  #
253
253
  # @since 2.1.0
254
254
  def command_name
255
- (filter[:$query] || !command?) ? FIND : filter.keys.first
255
+ command? ? filter.keys.first : FIND
256
256
  end
257
257
 
258
258
  private
@@ -261,13 +261,9 @@ module Mongo
261
261
  collection == Database::COMMAND
262
262
  end
263
263
 
264
- def query_filter
265
- filter[:$query] || filter
266
- end
267
-
268
264
  def op_command
269
265
  document = BSON::Document.new
270
- query_filter.each do |field, value|
266
+ filter.each do |field, value|
271
267
  document.store(field.to_s, value)
272
268
  end
273
269
  document
@@ -276,7 +272,7 @@ module Mongo
276
272
  def find_command
277
273
  document = BSON::Document.new
278
274
  document.store(FIND, collection)
279
- document.store(FILTER, query_filter)
275
+ document.store(FILTER, filter[:$query] ? filter[:$query] : filter)
280
276
  OPTION_MAPPINGS.each do |legacy, option|
281
277
  document.store(option, options[legacy]) unless options[legacy].nil?
282
278
  end
@@ -44,7 +44,7 @@ module Mongo
44
44
  attr_reader :monitoring
45
45
 
46
46
  # Get the description from the monitor and scan on monitor.
47
- def_delegators :monitor, :description, :scan!
47
+ def_delegators :monitor, :description, :scan!, :heartbeat_frequency, :last_scan
48
48
 
49
49
  # Delegate convenience methods to the monitor description.
50
50
  def_delegators :description,
@@ -64,7 +64,12 @@ module Mongo
64
64
  :secondary?,
65
65
  :standalone?,
66
66
  :unknown?,
67
- :unknown!
67
+ :unknown!,
68
+ :last_write_date
69
+
70
+ # Get the app metadata from the cluster.
71
+ def_delegators :cluster,
72
+ :app_metadata
68
73
 
69
74
  # Is this server equal to another?
70
75
  #
@@ -158,7 +163,7 @@ module Mongo
158
163
  @cluster = cluster
159
164
  @monitoring = monitoring
160
165
  @options = options.freeze
161
- @monitor = Monitor.new(address, event_listeners, options)
166
+ @monitor = Monitor.new(address, event_listeners, options.merge(app_metadata: cluster.app_metadata))
162
167
  monitor.scan!
163
168
  monitor.run!
164
169
  ObjectSpace.define_finalizer(self, self.class.finalize(monitor))