mongo 2.0.5 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/mongo/auth/cr/conversation.rb +0 -1
  5. data/lib/mongo/client.rb +19 -5
  6. data/lib/mongo/cluster.rb +84 -16
  7. data/lib/mongo/cluster/topology.rb +3 -4
  8. data/lib/mongo/cluster/topology/replica_set.rb +75 -0
  9. data/lib/mongo/cluster/topology/sharded.rb +60 -0
  10. data/lib/mongo/cluster/topology/single.rb +51 -0
  11. data/lib/mongo/cluster/topology/unknown.rb +62 -0
  12. data/lib/mongo/error/invalid_bulk_operation.rb +2 -1
  13. data/lib/mongo/event.rb +9 -9
  14. data/lib/mongo/event/{server_added.rb → description_changed.rb} +6 -5
  15. data/lib/mongo/event/{server_removed.rb → standalone_discovered.rb} +15 -15
  16. data/lib/mongo/operation/aggregate.rb +6 -5
  17. data/lib/mongo/operation/command.rb +5 -6
  18. data/lib/mongo/operation/kill_cursors.rb +3 -2
  19. data/lib/mongo/operation/map_reduce.rb +6 -5
  20. data/lib/mongo/operation/read/collections_info.rb +5 -4
  21. data/lib/mongo/operation/read/get_more.rb +8 -7
  22. data/lib/mongo/operation/read/indexes.rb +4 -3
  23. data/lib/mongo/operation/read/list_collections.rb +5 -4
  24. data/lib/mongo/operation/read/list_indexes.rb +7 -6
  25. data/lib/mongo/operation/read/query.rb +8 -7
  26. data/lib/mongo/operation/read_preferrable.rb +6 -2
  27. data/lib/mongo/operation/write/bulk/bulk_delete.rb +13 -12
  28. data/lib/mongo/operation/write/bulk/bulk_insert.rb +10 -9
  29. data/lib/mongo/operation/write/bulk/bulk_insert/result.rb +2 -2
  30. data/lib/mongo/operation/write/bulk/bulk_update.rb +12 -11
  31. data/lib/mongo/operation/write/create_index.rb +8 -7
  32. data/lib/mongo/operation/write/create_user.rb +4 -3
  33. data/lib/mongo/operation/write/delete.rb +13 -12
  34. data/lib/mongo/operation/write/drop_index.rb +6 -5
  35. data/lib/mongo/operation/write/insert.rb +8 -7
  36. data/lib/mongo/operation/write/insert/result.rb +1 -1
  37. data/lib/mongo/operation/write/remove_user.rb +4 -3
  38. data/lib/mongo/operation/write/update.rb +10 -9
  39. data/lib/mongo/operation/write/update_user.rb +4 -3
  40. data/lib/mongo/server.rb +8 -15
  41. data/lib/mongo/server/context.rb +2 -2
  42. data/lib/mongo/server/description.rb +65 -3
  43. data/lib/mongo/server/description/features.rb +2 -1
  44. data/lib/mongo/server/description/inspector.rb +5 -5
  45. data/lib/mongo/server/description/inspector/{server_added.rb → description_changed.rb} +3 -5
  46. data/lib/mongo/server/description/inspector/{server_removed.rb → standalone_discovered.rb} +12 -15
  47. data/lib/mongo/version.rb +1 -1
  48. data/spec/mongo/auth/cr_spec.rb +1 -1
  49. data/spec/mongo/auth/ldap_spec.rb +1 -1
  50. data/spec/mongo/auth/scram_spec.rb +1 -1
  51. data/spec/mongo/auth/x509_spec.rb +1 -1
  52. data/spec/mongo/client_spec.rb +4 -0
  53. data/spec/mongo/cluster/topology/replica_set_spec.rb +254 -4
  54. data/spec/mongo/cluster/topology/sharded_spec.rb +70 -19
  55. data/spec/mongo/cluster/topology/single_spec.rb +25 -4
  56. data/spec/mongo/cluster/topology/unknown_spec.rb +167 -0
  57. data/spec/mongo/cluster/topology_spec.rb +6 -6
  58. data/spec/mongo/cluster_spec.rb +179 -1
  59. data/spec/mongo/operation/read_preferrable_spec.rb +81 -28
  60. data/spec/mongo/operation/write/bulk/bulk_delete_spec.rb +1 -0
  61. data/spec/mongo/server/connection_pool_spec.rb +10 -10
  62. data/spec/mongo/server/connection_spec.rb +1 -1
  63. data/spec/mongo/server/description/features_spec.rb +23 -3
  64. data/spec/mongo/server/description/inspector/description_changed_spec.rb +78 -0
  65. data/spec/mongo/server/description_spec.rb +238 -0
  66. data/spec/mongo/server/monitor_spec.rb +1 -1
  67. data/spec/mongo/server_discovery_and_monitoring_spec.rb +20 -4
  68. data/spec/mongo/server_selection_spec.rb +2 -2
  69. data/spec/mongo/server_spec.rb +12 -8
  70. data/spec/support/authorization.rb +8 -8
  71. data/spec/support/sdam/rs/discover_passives.yml +36 -0
  72. data/spec/support/sdam/rs/new_primary_wrong_set_name.yml +2 -2
  73. data/spec/support/sdam/rs/primary_becomes_standalone.yml +1 -1
  74. data/spec/support/sdam/rs/primary_changes_set_name.yml +2 -2
  75. data/spec/support/sdam/rs/primary_disconnect.yml +1 -1
  76. data/spec/support/sdam/rs/primary_wrong_set_name.yml +1 -1
  77. data/spec/support/sdam/rs/secondary_wrong_set_name.yml +1 -1
  78. data/spec/support/sdam/rs/secondary_wrong_set_name_with_primary.yml +2 -2
  79. data/spec/support/sdam/sharded/single_mongos.yml +33 -0
  80. data/spec/support/shared/operation.rb +12 -4
  81. data/spec/support/shared/server_selector.rb +1 -1
  82. metadata +12 -10
  83. metadata.gz.sig +0 -0
  84. data/spec/mongo/server/description/inspector/server_added_spec.rb +0 -92
  85. data/spec/mongo/server/description/inspector/server_removed_spec.rb +0 -95
@@ -33,16 +33,17 @@ module Mongo
33
33
  # :ordered => false
34
34
  # })
35
35
  #
36
- # @param [ Hash ] spec The specifications for the insert.
36
+ # Initialization:
37
+ # param [ Hash ] spec The specifications for the insert.
37
38
  #
38
- # @option spec :documents [ Array ] The documents to insert.
39
- # @option spec :db_name [ String ] The name of the database.
40
- # @option spec :coll_name [ String ] The name of the collection.
41
- # @option spec :write_concern [ Mongo::WriteConcern ] The write concern.
42
- # @option spec :ordered [ true, false ] Whether the operations should be
43
- # executed in order.
44
- # @option spec :options [ Hash ] Options for the command, if it ends up being a
45
- # write command.
39
+ # option spec :documents [ Array ] The documents to insert.
40
+ # option spec :db_name [ String ] The name of the database.
41
+ # option spec :coll_name [ String ] The name of the collection.
42
+ # option spec :write_concern [ Mongo::WriteConcern ] The write concern.
43
+ # option spec :ordered [ true, false ] Whether the operations should be
44
+ # executed in order.
45
+ # option spec :options [ Hash ] Options for the command, if it ends up being a
46
+ # write command.
46
47
  #
47
48
  # @since 2.0.0
48
49
  class BulkInsert
@@ -37,7 +37,7 @@ module Mongo
37
37
  # Result.new(replies, inserted_ids)
38
38
  #
39
39
  # @param [ Protocol::Reply ] replies The wire protocol replies.
40
- # @params [ Array<Object> ] ids The ids of the inserted documents.
40
+ # @param [ Array<Object> ] ids The ids of the inserted documents.
41
41
  #
42
42
  # @since 2.0.0
43
43
  def initialize(replies, ids)
@@ -88,7 +88,7 @@ module Mongo
88
88
  # Result.new(replies, inserted_ids)
89
89
  #
90
90
  # @param [ Protocol::Reply ] replies The wire protocol replies.
91
- # @params [ Array<Object> ] ids The ids of the inserted documents.
91
+ # @param [ Array<Object> ] ids The ids of the inserted documents.
92
92
  #
93
93
  # @since 2.0.0
94
94
  def initialize(replies, ids)
@@ -39,18 +39,19 @@ module Mongo
39
39
  # :ordered => false
40
40
  # })
41
41
  #
42
- # @param [ Hash ] spec The specifications for the update.
42
+ # Initialization:
43
+ # param [ Hash ] spec The specifications for the update.
43
44
  #
44
- # @option spec :updates [ Array ] The update documents.
45
- # @option spec :db_name [ String ] The name of the database on which
46
- # the query should be run.
47
- # @option spec :coll_name [ String ] The name of the collection on which
48
- # the query should be run.
49
- # @option spec :write_concern [ Mongo::WriteConcern ] The write concern.
50
- # @option spec :ordered [ true, false ] Whether the operations should be
51
- # executed in order.
52
- # @option spec :options [ Hash ] Options for the command, if it ends up being a
53
- # write command.
45
+ # option spec :updates [ Array ] The update documents.
46
+ # option spec :db_name [ String ] The name of the database on which
47
+ # the query should be run.
48
+ # option spec :coll_name [ String ] The name of the collection on which
49
+ # the query should be run.
50
+ # option spec :write_concern [ Mongo::WriteConcern ] The write concern.
51
+ # option spec :ordered [ true, false ] Whether the operations should be
52
+ # executed in order.
53
+ # option spec :options [ Hash ] Options for the command, if it ends up being a
54
+ # write command.
54
55
  #
55
56
  # @since 2.0.0
56
57
  class BulkUpdate
@@ -30,14 +30,15 @@ module Mongo
30
30
  # :index_name => 'name_1_age_-1'
31
31
  # })
32
32
  #
33
- # @param [ Hash ] spec The specifications for the insert.
33
+ # Initialization:
34
+ # param [ Hash ] spec The specifications for the insert.
34
35
  #
35
- # @option spec :index [ Hash ] The index spec to create.
36
- # @option spec :db_name [ String ] The name of the database.
37
- # @option spec :coll_name [ String ] The name of the collection.
38
- # @option spec :index_name [ String ] The name of the index.
39
- # @option spec :options [ Hash ] Options for the command, if it ends up being a
40
- # write command.
36
+ # option spec :index [ Hash ] The index spec to create.
37
+ # option spec :db_name [ String ] The name of the database.
38
+ # option spec :coll_name [ String ] The name of the collection.
39
+ # option spec :index_name [ String ] The name of the index.
40
+ # option spec :options [ Hash ] Options for the command, if it ends up being a
41
+ # write command.
41
42
  #
42
43
  # @since 2.0.0
43
44
  class CreateIndex
@@ -22,10 +22,11 @@ module Mongo
22
22
  # @example Initialize the operation.
23
23
  # Write::CreateUser.new(:db_name => 'test', :user => user)
24
24
  #
25
- # @param [ Hash ] spec The specifications for the create.
25
+ # Initialization:
26
+ # param [ Hash ] spec The specifications for the create.
26
27
  #
27
- # @option spec :user [ Auth::User ] The user to create.
28
- # @option spec :db_name [ String ] The name of the database.
28
+ # option spec :user [ Auth::User ] The user to create.
29
+ # option spec :db_name [ String ] The name of the database.
29
30
  #
30
31
  # @since 2.0.0
31
32
  class CreateUser
@@ -31,19 +31,20 @@ module Mongo
31
31
  # :write_concern => write_concern
32
32
  # })
33
33
  #
34
- # @param [ Hash ] spec The specifications for the delete.
34
+ # Initialization:
35
+ # param [ Hash ] spec The specifications for the delete.
35
36
  #
36
- # @option spec :delete [ Hash ] The delete document.
37
- # @option spec :db_name [ String ] The name of the database on which
38
- # the delete should be executed.
39
- # @option spec :coll_name [ String ] The name of the collection on which
40
- # the delete should be executed.
41
- # @option spec :write_concern [ Mongo::WriteConcern ] The write concern
42
- # for this operation.
43
- # @option spec :ordered [ true, false ] Whether the operations should be
44
- # executed in order.
45
- # @option spec :options [Hash] Options for the command, if it ends up being a
46
- # write command.
37
+ # option spec :delete [ Hash ] The delete document.
38
+ # option spec :db_name [ String ] The name of the database on which
39
+ # the delete should be executed.
40
+ # option spec :coll_name [ String ] The name of the collection on which
41
+ # the delete should be executed.
42
+ # option spec :write_concern [ Mongo::WriteConcern ] The write concern
43
+ # for this operation.
44
+ # option spec :ordered [ true, false ] Whether the operations should be
45
+ # executed in order.
46
+ # option spec :options [Hash] Options for the command, if it ends up being a
47
+ # write command.
47
48
  #
48
49
  # @since 2.0.0
49
50
  class Delete
@@ -25,12 +25,13 @@ module Mongo
25
25
  # :index_name => 'name_1_age_-1'
26
26
  # })
27
27
  #
28
- # @param [ Hash ] spec The specifications for the drop.
28
+ # Initialization:
29
+ # param [ Hash ] spec The specifications for the drop.
29
30
  #
30
- # @option spec :index [ Hash ] The index spec to create.
31
- # @option spec :db_name [ String ] The name of the database.
32
- # @option spec :coll_name [ String ] The name of the collection.
33
- # @option spec :index_name [ String ] The name of the index.
31
+ # option spec :index [ Hash ] The index spec to create.
32
+ # option spec :db_name [ String ] The name of the database.
33
+ # option spec :coll_name [ String ] The name of the collection.
34
+ # option spec :index_name [ String ] The name of the index.
34
35
  #
35
36
  # @since 2.0.0
36
37
  class DropIndex
@@ -31,14 +31,15 @@ module Mongo
31
31
  # :write_concern => write_concern
32
32
  # })
33
33
  #
34
- # @param [ Hash ] spec The specifications for the insert.
34
+ # Initialization:
35
+ # param [ Hash ] spec The specifications for the insert.
35
36
  #
36
- # @option spec :documents [ Array ] The documents to insert.
37
- # @option spec :db_name [ String ] The name of the database.
38
- # @option spec :coll_name [ String ] The name of the collection.
39
- # @option spec :write_concern [ Mongo::WriteConcern ] The write concern.
40
- # @option spec :options [ Hash ] Options for the command, if it ends up being a
41
- # write command.
37
+ # option spec :documents [ Array ] The documents to insert.
38
+ # option spec :db_name [ String ] The name of the database.
39
+ # option spec :coll_name [ String ] The name of the collection.
40
+ # option spec :write_concern [ Mongo::WriteConcern ] The write concern.
41
+ # option spec :options [ Hash ] Options for the command, if it ends up being a
42
+ # write command.
42
43
  #
43
44
  # @since 2.0.0
44
45
  class Insert
@@ -36,7 +36,7 @@ module Mongo
36
36
  # Result.new(replies, inserted_ids)
37
37
  #
38
38
  # @param [ Protocol::Reply ] replies The wire protocol replies.
39
- # @params [ Array<Object> ] ids The ids of the inserted documents.
39
+ # @param [ Array<Object> ] ids The ids of the inserted documents.
40
40
  #
41
41
  # @since 2.0.0
42
42
  def initialize(replies, ids)
@@ -21,10 +21,11 @@ module Mongo
21
21
  # @example Create the remove user operation.
22
22
  # Write::RemoveUser.new(:db_name => 'test', :name => name)
23
23
  #
24
- # @param [ Hash ] spec The specifications for the remove.
24
+ # Initialization:
25
+ # param [ Hash ] spec The specifications for the remove.
25
26
  #
26
- # @option spec :name [ String ] The user name.
27
- # @option spec :db_name [ String ] The name of the database.
27
+ # option spec :name [ String ] The user name.
28
+ # option spec :db_name [ String ] The name of the database.
28
29
  #
29
30
  # @since 2.0.0
30
31
  class RemoveUser
@@ -37,16 +37,17 @@ module Mongo
37
37
  # :write_concern => write_concern
38
38
  # })
39
39
  #
40
- # @param [ Hash ] spec The specifications for the update.
40
+ # Initialization:
41
+ # param [ Hash ] spec The specifications for the update.
41
42
  #
42
- # @option spec :update [ Hash ] The update document.
43
- # @option spec :db_name [ String ] The name of the database on which
44
- # the query should be run.
45
- # @option spec :coll_name [ String ] The name of the collection on which
46
- # the query should be run.
47
- # @option spec :write_concern [ Mongo::WriteConcern ] The write concern.
48
- # @option spec :options [ Hash ] Options for the command, if it ends up being a
49
- # write command.
43
+ # option spec :update [ Hash ] The update document.
44
+ # option spec :db_name [ String ] The name of the database on which
45
+ # the query should be run.
46
+ # option spec :coll_name [ String ] The name of the collection on which
47
+ # the query should be run.
48
+ # option spec :write_concern [ Mongo::WriteConcern ] The write concern.
49
+ # option spec :options [ Hash ] Options for the command, if it ends up being a
50
+ # write command.
50
51
  #
51
52
  # @since 2.0.0
52
53
  class Update
@@ -22,10 +22,11 @@ module Mongo
22
22
  # @example Initialize the operation.
23
23
  # Write::UpdateUser.new(:db_name => 'test', :user => user)
24
24
  #
25
- # @param [ Hash ] spec The specifications for the update.
25
+ # Initialization:
26
+ # param [ Hash ] spec The specifications for the update.
26
27
  #
27
- # @option spec :user [ Auth::User ] The user to update.
28
- # @option spec :db_name [ String ] The name of the database.
28
+ # option spec :user [ Auth::User ] The user to update.
29
+ # option spec :db_name [ String ] The name of the database.
29
30
  #
30
31
  # @since 2.0.0
31
32
  class UpdateUser
@@ -31,6 +31,9 @@ module Mongo
31
31
  # @return [ String ] The configured address for the server.
32
32
  attr_reader :address
33
33
 
34
+ # @return [ Cluster ] cluster The server cluster.
35
+ attr_reader :cluster
36
+
34
37
  # @return [ Monitor ] monitor The server monitor.
35
38
  attr_reader :monitor
36
39
 
@@ -105,15 +108,17 @@ module Mongo
105
108
  # subscribe to the appropriate events.
106
109
  #
107
110
  # @example Initialize the server.
108
- # Mongo::Server.new('127.0.0.1:27017', listeners)
111
+ # Mongo::Server.new('127.0.0.1:27017', cluster, listeners)
109
112
  #
110
113
  # @param [ Address ] address The host:port address to connect to.
114
+ # @param [ Cluster ] cluster The cluster the server belongs to.
111
115
  # @param [ Event::Listeners ] event_listeners The event listeners.
112
116
  # @param [ Hash ] options The server options.
113
117
  #
114
118
  # @since 2.0.0
115
- def initialize(address, event_listeners, options = {})
119
+ def initialize(address, cluster, event_listeners, options = {})
116
120
  @address = address
121
+ @cluster = cluster
117
122
  @options = options.freeze
118
123
  @monitor = Monitor.new(address, event_listeners, options)
119
124
  monitor.scan!
@@ -123,7 +128,7 @@ module Mongo
123
128
  # Get a pretty printed server inspection.
124
129
  #
125
130
  # @example Get the server inspection.
126
- # server.inspec
131
+ # server.inspect
127
132
  #
128
133
  # @return [ String ] The nice inspection string.
129
134
  #
@@ -159,17 +164,5 @@ module Mongo
159
164
  tags[k] && tags[k] == tag_set[k]
160
165
  end
161
166
  end
162
-
163
- # Whether the slaveOk bit must be set for all queries sent to the server.
164
- #
165
- # @example Does the slaveOk bit need to be set for all queries sent to the server.
166
- # server.slave_ok?
167
- #
168
- # @return [ true, false ] If the slaveOk bit needs to be set for all queries.
169
- #
170
- # @since 2.0.0
171
- def slave_ok?
172
- options[:slave_ok]
173
- end
174
167
  end
175
168
  end
@@ -27,14 +27,14 @@ module Mongo
27
27
 
28
28
  # Delegate state checks to the server.
29
29
  def_delegators :@server,
30
+ :cluster,
30
31
  :features,
31
32
  :max_wire_version,
32
33
  :max_write_batch_size,
33
34
  :mongos?,
34
35
  :primary?,
35
36
  :secondary?,
36
- :standalone?,
37
- :slave_ok?
37
+ :standalone?
38
38
 
39
39
  # Instantiate a server context.
40
40
  #
@@ -124,6 +124,11 @@ module Mongo
124
124
  # @since 2.0.0
125
125
  TAGS = 'tags'.freeze
126
126
 
127
+ # Fields to exclude when comparing two descriptions.
128
+ #
129
+ # @since 2.0.6
130
+ EXCLUDE_FOR_COMPARISON = [ 'localTime' ]
131
+
127
132
  # @return [ Address ] address The server's address.
128
133
  attr_reader :address
129
134
 
@@ -157,7 +162,7 @@ module Mongo
157
162
  #
158
163
  # @since 2.0.0
159
164
  def arbiters
160
- config[ARBITERS] || []
165
+ @arbiters ||= (config[ARBITERS] || []).map { |s| s.downcase }
161
166
  end
162
167
 
163
168
  # Is the server a ghost in a replica set?
@@ -193,7 +198,7 @@ module Mongo
193
198
  #
194
199
  # @since 2.0.0
195
200
  def hosts
196
- config[HOSTS] || []
201
+ @hosts ||= (config[HOSTS] || []).map { |s| s.downcase }
197
202
  end
198
203
 
199
204
  # Instantiate the new server description from the result of the ismaster
@@ -344,7 +349,7 @@ module Mongo
344
349
  #
345
350
  # @since 2.0.0
346
351
  def passives
347
- config[PASSIVES] || []
352
+ @passives ||= (config[PASSIVES] || []).map { |s| s.downcase }
348
353
  end
349
354
 
350
355
  # Will return true if the server is a primary.
@@ -445,6 +450,63 @@ module Mongo
445
450
  def wire_versions
446
451
  min_wire_version..max_wire_version
447
452
  end
453
+
454
+ # Is this description from the given server.
455
+ #
456
+ # @example Check if the description is from a given server.
457
+ # description.is_server?(server)
458
+ #
459
+ # @return [ true, false ] If the description is from the server.
460
+ #
461
+ # @since 2.0.6
462
+ def is_server?(server)
463
+ address == server.address
464
+ end
465
+
466
+ # Is a server included in this description's list of servers.
467
+ #
468
+ # @example Check if a server is in the description list of servers.
469
+ # description.lists_server?(server)
470
+ #
471
+ # @return [ true, false ] If a server is in the description's list
472
+ # of servers.
473
+ #
474
+ # @since 2.0.6
475
+ def lists_server?(server)
476
+ servers.include?(server.address.to_s)
477
+ end
478
+
479
+ # Does this description correspond to a replica set member.
480
+ #
481
+ # @example Check if the description is from a replica set member.
482
+ # description.replica_set_member?
483
+ #
484
+ # @return [ true, false ] If the description is from a replica set
485
+ # member.
486
+ #
487
+ # @since 2.0.6
488
+ def replica_set_member?
489
+ !(standalone? || mongos?)
490
+ end
491
+
492
+ # Check equality of two descriptions.
493
+ #
494
+ # @example Check description equality.
495
+ # description == other
496
+ #
497
+ # @param [ Object ] other The other description.
498
+ #
499
+ # @return [ true, false ] Whether the objects are equal.
500
+ #
501
+ # @since 2.0.6
502
+ def ==(other)
503
+ return false if self.class != other.class
504
+ return true if config == other.config
505
+ !config.keys.empty? && config.keys.all? do |k|
506
+ config[k] == other.config[k] || EXCLUDE_FOR_COMPARISON.include?(k)
507
+ end
508
+ end
509
+ alias_method :eql?, :==
448
510
  end
449
511
  end
450
512
  end
@@ -75,7 +75,8 @@ module Mongo
75
75
  private
76
76
 
77
77
  def check_driver_support!
78
- if DRIVER_WIRE_VERSIONS.max < server_wire_versions.max
78
+ if DRIVER_WIRE_VERSIONS.max < server_wire_versions.min ||
79
+ DRIVER_WIRE_VERSIONS.min > server_wire_versions.max
79
80
  raise Error::UnsupportedFeatures.new(server_wire_versions)
80
81
  end
81
82
  end