mongo 2.0.6 → 2.1.0.beta

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 (119) 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.rb +2 -0
  5. data/lib/mongo/bulk_write.rb +1 -0
  6. data/lib/mongo/bulk_write/bulk_writable.rb +87 -31
  7. data/lib/mongo/bulk_write/deletable.rb +8 -7
  8. data/lib/mongo/bulk_write/insertable.rb +4 -3
  9. data/lib/mongo/bulk_write/ordered_bulk_write.rb +6 -6
  10. data/lib/mongo/bulk_write/replacable.rb +4 -3
  11. data/lib/mongo/bulk_write/result.rb +138 -0
  12. data/lib/mongo/bulk_write/unordered_bulk_write.rb +5 -8
  13. data/lib/mongo/bulk_write/updatable.rb +8 -7
  14. data/lib/mongo/client.rb +36 -4
  15. data/lib/mongo/cluster.rb +39 -4
  16. data/lib/mongo/cluster/topology/replica_set.rb +20 -4
  17. data/lib/mongo/cluster/topology/sharded.rb +1 -1
  18. data/lib/mongo/collection.rb +282 -29
  19. data/lib/mongo/collection/view/aggregation.rb +32 -4
  20. data/lib/mongo/collection/view/iterable.rb +2 -1
  21. data/lib/mongo/collection/view/map_reduce.rb +3 -1
  22. data/lib/mongo/collection/view/readable.rb +89 -14
  23. data/lib/mongo/collection/view/writable.rb +11 -5
  24. data/lib/mongo/cursor.rb +11 -3
  25. data/lib/mongo/dbref.rb +113 -0
  26. data/lib/mongo/error.rb +6 -2
  27. data/lib/mongo/error/parser.rb +1 -1
  28. data/lib/mongo/event/description_changed.rb +1 -1
  29. data/lib/mongo/grid/file.rb +1 -1
  30. data/lib/mongo/grid/fs.rb +2 -5
  31. data/lib/mongo/monitoring.rb +199 -0
  32. data/lib/mongo/monitoring/command_log_subscriber.rb +88 -0
  33. data/lib/mongo/monitoring/event.rb +17 -0
  34. data/lib/mongo/monitoring/event/command_failed.rb +96 -0
  35. data/lib/mongo/monitoring/event/command_started.rb +88 -0
  36. data/lib/mongo/monitoring/event/command_succeeded.rb +96 -0
  37. data/lib/mongo/monitoring/publishable.rb +96 -0
  38. data/lib/mongo/operation.rb +1 -0
  39. data/lib/mongo/operation/executable.rb +1 -1
  40. data/lib/mongo/operation/parallel_scan.rb +76 -0
  41. data/lib/mongo/operation/parallel_scan/result.rb +72 -0
  42. data/lib/mongo/operation/specifiable.rb +18 -0
  43. data/lib/mongo/operation/write/bulk/bulk_delete.rb +1 -1
  44. data/lib/mongo/operation/write/bulk/bulk_insert.rb +1 -1
  45. data/lib/mongo/operation/write/bulk/bulk_mergable.rb +2 -2
  46. data/lib/mongo/operation/write/bulk/bulk_update.rb +1 -1
  47. data/lib/mongo/operation/write/bulk/bulk_update/result.rb +13 -1
  48. data/lib/mongo/protocol/delete.rb +8 -13
  49. data/lib/mongo/protocol/get_more.rb +13 -13
  50. data/lib/mongo/protocol/insert.rb +8 -13
  51. data/lib/mongo/protocol/kill_cursors.rb +7 -11
  52. data/lib/mongo/protocol/query.rb +58 -20
  53. data/lib/mongo/protocol/reply.rb +12 -0
  54. data/lib/mongo/protocol/update.rb +13 -14
  55. data/lib/mongo/server.rb +23 -2
  56. data/lib/mongo/server/connectable.rb +0 -22
  57. data/lib/mongo/server/connection.rb +29 -0
  58. data/lib/mongo/server/description.rb +23 -1
  59. data/lib/mongo/server/monitor.rb +17 -1
  60. data/lib/mongo/server/monitor/connection.rb +24 -0
  61. data/lib/mongo/socket/ssl.rb +28 -16
  62. data/lib/mongo/socket/tcp.rb +1 -1
  63. data/lib/mongo/socket/unix.rb +1 -1
  64. data/lib/mongo/uri.rb +12 -5
  65. data/lib/mongo/version.rb +1 -1
  66. data/spec/mongo/auth/cr_spec.rb +9 -1
  67. data/spec/mongo/auth/ldap_spec.rb +9 -1
  68. data/spec/mongo/auth/scram_spec.rb +9 -1
  69. data/spec/mongo/auth/x509_spec.rb +9 -1
  70. data/spec/mongo/{bulk/bulk_write_spec.rb → bulk_write_spec.rb} +15 -15
  71. data/spec/mongo/client_spec.rb +42 -0
  72. data/spec/mongo/cluster/topology/replica_set_spec.rb +16 -9
  73. data/spec/mongo/cluster/topology/sharded_spec.rb +11 -3
  74. data/spec/mongo/cluster/topology/single_spec.rb +12 -4
  75. data/spec/mongo/cluster_spec.rb +55 -10
  76. data/spec/mongo/collection/view/aggregation_spec.rb +123 -1
  77. data/spec/mongo/collection/view/explainable_spec.rb +1 -1
  78. data/spec/mongo/collection/view/map_reduce_spec.rb +1 -1
  79. data/spec/mongo/collection/view/readable_spec.rb +251 -6
  80. data/spec/mongo/collection/view/writable_spec.rb +4 -4
  81. data/spec/mongo/collection/view_spec.rb +233 -71
  82. data/spec/mongo/collection_spec.rb +905 -9
  83. data/spec/mongo/crud_spec.rb +2 -2
  84. data/spec/mongo/cursor_spec.rb +3 -3
  85. data/spec/mongo/dbref_spec.rb +149 -0
  86. data/spec/mongo/monitoring_spec.rb +168 -0
  87. data/spec/mongo/operation/map_reduce_spec.rb +1 -1
  88. data/spec/mongo/operation/write/bulk/bulk_delete_spec.rb +1 -1
  89. data/spec/mongo/operation/write/bulk/bulk_insert_spec.rb +2 -2
  90. data/spec/mongo/operation/write/bulk/bulk_update_spec.rb +1 -1
  91. data/spec/mongo/operation/write/delete_spec.rb +1 -1
  92. data/spec/mongo/operation/write/insert_spec.rb +2 -2
  93. data/spec/mongo/operation/write/update_spec.rb +1 -1
  94. data/spec/mongo/protocol/query_spec.rb +0 -29
  95. data/spec/mongo/server/connection_pool_spec.rb +18 -6
  96. data/spec/mongo/server/connection_spec.rb +12 -4
  97. data/spec/mongo/server/description_spec.rb +7 -3
  98. data/spec/mongo/server/monitor_spec.rb +30 -0
  99. data/spec/mongo/server_discovery_and_monitoring_spec.rb +11 -4
  100. data/spec/mongo/server_selection_spec.rb +14 -6
  101. data/spec/mongo/server_spec.rb +27 -8
  102. data/spec/mongo/socket/ssl_spec.rb +94 -8
  103. data/spec/mongo/uri_spec.rb +25 -9
  104. data/spec/spec_helper.rb +29 -20
  105. data/spec/support/authorization.rb +19 -4
  106. data/spec/support/certificates/client.pem +4 -4
  107. data/spec/support/crud/read.rb +9 -10
  108. data/spec/support/crud/write.rb +24 -20
  109. data/spec/support/sdam/rs/equal_electionids.yml +45 -0
  110. data/spec/support/sdam/rs/new_primary_new_electionid.yml +98 -0
  111. data/spec/support/sdam/rs/null_election_id.yml +144 -0
  112. data/spec/support/sdam/rs/primary_disconnect_electionid.yml +124 -0
  113. data/spec/support/sdam/sharded/mongos_disconnect.yml +104 -0
  114. data/spec/support/server_discovery_and_monitoring.rb +19 -2
  115. data/spec/support/shared/bulk_write.rb +26 -22
  116. data/spec/support/shared/server_selector.rb +2 -1
  117. metadata +31 -7
  118. metadata.gz.sig +0 -0
  119. data/lib/mongo/error/invalid_uri_option.rb +0 -38
@@ -129,11 +129,11 @@ describe Mongo::URI do
129
129
  describe '#database' do
130
130
  let(:servers) { 'localhost' }
131
131
  let(:string) { "#{scheme}#{servers}/#{db}" }
132
- let(:db) { TEST_DB }
132
+ let(:db) { 'auth-db' }
133
133
 
134
134
  context 'database provided' do
135
135
  it 'returns the database name' do
136
- expect(uri.database).to eq(TEST_DB)
136
+ expect(uri.database).to eq(db)
137
137
  end
138
138
  end
139
139
  end
@@ -171,7 +171,7 @@ describe Mongo::URI do
171
171
  end
172
172
 
173
173
  context 'journal' do
174
- let(:options) { 'j=true' }
174
+ let(:options) { 'journal=true' }
175
175
  let(:concern) { { :j => true } }
176
176
 
177
177
  it 'sets the write concern options' do
@@ -248,7 +248,7 @@ describe Mongo::URI do
248
248
  end
249
249
  end
250
250
 
251
- context 'read preferece tags provided' do
251
+ context 'read preference tags provided' do
252
252
 
253
253
  context 'single read preference tag set' do
254
254
  let(:options) do
@@ -505,12 +505,28 @@ describe Mongo::URI do
505
505
 
506
506
  context 'when an invalid option is provided' do
507
507
 
508
- let(:options) { 'iDontKnow=10' }
508
+ let(:options) { 'invalidOption=10' }
509
509
 
510
- it 'raises an exception' do
511
- expect {
512
- uri.options
513
- }.to raise_error(Mongo::Error::InvalidURIOption)
510
+ let(:uri_options) do
511
+ uri.options
512
+ end
513
+
514
+ it 'does not raise an exception' do
515
+ expect(uri_options).to be_empty
516
+ end
517
+
518
+ context 'when an invalid option is combined with valid options' do
519
+
520
+ let(:options) { 'invalidOption=10&waitQueueTimeoutMS=500&ssl=true' }
521
+
522
+ it 'does not raise an exception' do
523
+ expect(uri_options).not_to be_empty
524
+ end
525
+
526
+ it 'sets the valid options' do
527
+ expect(uri_options[:wait_queue_timeout]).to eq(0.5)
528
+ expect(uri_options[:ssl]).to be true
529
+ end
514
530
  end
515
531
  end
516
532
  end
@@ -17,6 +17,20 @@ if RUBY_VERSION > '1.9' && RUBY_VERSION < '2.2'
17
17
  end
18
18
  end
19
19
 
20
+ TEST_SET = 'ruby-driver-rs'
21
+ COVERAGE_MIN = 90
22
+ CURRENT_PATH = File.expand_path(File.dirname(__FILE__))
23
+ SERVER_DISCOVERY_TESTS = Dir.glob("#{CURRENT_PATH}/support/sdam/**/*.yml")
24
+ SERVER_SELECTION_RTT_TESTS = Dir.glob("#{CURRENT_PATH}/support/server_selection/rtt/*.yml")
25
+ SERVER_SELECTION_TESTS = Dir.glob("#{CURRENT_PATH}/support/server_selection/selection/**/*.yml")
26
+ CRUD_TESTS = Dir.glob("#{CURRENT_PATH}/support/crud_tests/**/*.yml")
27
+
28
+ SSL_CERTS_DIR = "#{CURRENT_PATH}/support/certificates"
29
+ CLIENT_PEM = "#{SSL_CERTS_DIR}/client.pem"
30
+ CLIENT_PASSWORD_PEM = "#{SSL_CERTS_DIR}/password_protected.pem"
31
+ CA_PEM = "#{SSL_CERTS_DIR}/ca.pem"
32
+ CRL_PEM = "#{SSL_CERTS_DIR}/crl.pem"
33
+
20
34
  require 'mongo'
21
35
 
22
36
  require 'support/travis'
@@ -61,20 +75,6 @@ RSpec.configure do |config|
61
75
  end
62
76
  end
63
77
 
64
- TEST_SET = 'ruby-driver-rs'
65
- COVERAGE_MIN = 90
66
- CURRENT_PATH = File.expand_path(File.dirname(__FILE__))
67
- SERVER_DISCOVERY_TESTS = Dir.glob("#{CURRENT_PATH}/support/sdam/**/*.yml")
68
- SERVER_SELECTION_RTT_TESTS = Dir.glob("#{CURRENT_PATH}/support/server_selection/rtt/*.yml")
69
- SERVER_SELECTION_TESTS = Dir.glob("#{CURRENT_PATH}/support/server_selection/selection/**/*.yml")
70
- CRUD_TESTS = Dir.glob("#{CURRENT_PATH}/support/crud_tests/**/*.yml")
71
-
72
- SSL_CERTS_DIR = "#{CURRENT_PATH}/support/certificates"
73
- CLIENT_PEM = "#{SSL_CERTS_DIR}/client.pem"
74
- CLIENT_PASSWORD_PEM = "#{SSL_CERTS_DIR}/password_protected.pem"
75
- CA_PEM = "#{SSL_CERTS_DIR}/ca.pem"
76
- CRL_PEM = "#{SSL_CERTS_DIR}/crl.pem"
77
-
78
78
  # Determine whether the test clients are connecting to a standalone.
79
79
  #
80
80
  # @since 2.0.0
@@ -91,12 +91,13 @@ def replica_set?
91
91
  $replica_set ||= $mongo_client.cluster.replica_set?
92
92
  end
93
93
 
94
- # Determine whether the test clients are connecting to a sharded cluster.
94
+ # Determine whether the test clients are connecting to a sharded cluster
95
+ # or a single mongos.
95
96
  #
96
97
  # @since 2.0.0
97
98
  def sharded?
98
99
  $mongo_client ||= initialize_scanned_client!
99
- $sharded ||= $mongo_client.cluster.sharded?
100
+ $sharded ||= ($mongo_client.cluster.sharded? || single_mongos?)
100
101
  end
101
102
 
102
103
  # Determine whether the single address provided is a replica set member.
@@ -107,7 +108,8 @@ end
107
108
  # @since 2.0.0
108
109
  def single_rs_member?
109
110
  $mongo_client ||= initialize_scanned_client!
110
- single_seed? && $mongo_client.cluster.servers.first.replica_set_name
111
+ $single_rs_member ||= (single_seed? &&
112
+ $mongo_client.cluster.servers.first.replica_set_name)
111
113
  end
112
114
 
113
115
  # Determine whether the single address provided is a mongos.
@@ -118,7 +120,8 @@ end
118
120
  # @since 2.0.0
119
121
  def single_mongos?
120
122
  $mongo_client ||= initialize_scanned_client!
121
- single_seed? && $mongo_client.cluster.servers.first.mongos?
123
+ $single_mongos ||= (single_seed? &&
124
+ $mongo_client.cluster.servers.first.mongos?)
122
125
  end
123
126
 
124
127
  # Determine whether a single address was provided.
@@ -146,10 +149,16 @@ def list_command_enabled?
146
149
  $list_command_enabled ||= $mongo_client.cluster.servers.first.features.list_indexes_enabled?
147
150
  end
148
151
 
149
- def testing_locally?
150
- !(ENV['CI'] || ENV['JENKINS_HOME'])
152
+ # Is the test suite running locally (not on Travis or Jenkins).
153
+ #
154
+ # @since 2.1.0
155
+ def testing_ssl_locally?
156
+ running_ssl? && !(ENV['CI'] || ENV['JENKINS_CI'])
151
157
  end
152
158
 
159
+ # Is the test suite running on SSL.
160
+ #
161
+ # @since 2.0.2
153
162
  def running_ssl?
154
163
  SSL
155
164
  end
@@ -50,13 +50,28 @@ WRITE_CONCERN = CONNECT[:connect] == :replica_set ? { w: ADDRESSES.size } : { w:
50
50
  # @since 2.0.3
51
51
  SSL = ENV['SSL_ENABLED'] == 'true'
52
52
 
53
+ # SSL options.
54
+ #
55
+ # @since 2.1.0
56
+ SSL_OPTIONS = {
57
+ ssl: SSL,
58
+ ssl_verify: false,
59
+ ssl_cert: CLIENT_PEM,
60
+ ssl_key: CLIENT_PEM
61
+ }
62
+
63
+ # Base test options.
64
+ #
65
+ # @since 2.1.0
66
+ BASE_OPTIONS = {
67
+ max_pool_size: 1,
68
+ write: WRITE_CONCERN
69
+ }
70
+
53
71
  # Options for test suite clients.
54
72
  #
55
73
  # @since 2.0.3
56
- TEST_OPTIONS = CONNECT.merge(max_pool_size: 1,
57
- write: WRITE_CONCERN,
58
- ssl: SSL,
59
- server_selection_timeout: 3)
74
+ TEST_OPTIONS = BASE_OPTIONS.merge(CONNECT).merge(SSL_OPTIONS)
60
75
 
61
76
  # The root user name.
62
77
  #
@@ -32,13 +32,13 @@ Certificate:
32
32
  6e:a7
33
33
  Exponent: 65537 (0x10001)
34
34
  X509v3 extensions:
35
- X509v3 Basic Constraints:
35
+ X509v3 Basic Constraints:
36
36
  CA:FALSE
37
- Netscape Comment:
37
+ Netscape Comment:
38
38
  OpenSSL Generated Certificate
39
- X509v3 Subject Key Identifier:
39
+ X509v3 Subject Key Identifier:
40
40
  4A:8B:EE:22:42:E6:F8:62:4C:86:38:8D:C5:78:95:98:C1:10:05:7C
41
- X509v3 Authority Key Identifier:
41
+ X509v3 Authority Key Identifier:
42
42
  keyid:07:41:19:3A:9F:7E:C5:B7:22:4E:B7:BC:D5:DF:E4:FC:09:B8:64:16
43
43
 
44
44
  Signature Algorithm: sha1WithRSAEncryption
@@ -93,30 +93,29 @@ module Mongo
93
93
  private
94
94
 
95
95
  def count(collection)
96
- view = collection.find(filter)
97
96
  options = ARGUMENT_MAP.reduce({}) do |opts, (key, value)|
98
97
  opts.merge!(key => arguments[value]) if arguments[value]
99
98
  opts
100
99
  end
101
- view.count(options)
100
+ collection.count(filter, options)
102
101
  end
103
102
 
104
103
  def aggregate(collection)
105
- collection.find.tap do |view|
106
- view = view.batch_size(batch_size) if batch_size
107
- end.aggregate(pipeline).to_a
104
+ collection.aggregate(pipeline, options).to_a
108
105
  end
109
106
 
110
107
  def distinct(collection)
111
- collection.find(filter).distinct(field_name)
108
+ collection.distinct(field_name, filter, options)
112
109
  end
113
110
 
114
111
  def find(collection)
115
- view = collection.find(filter)
116
- ARGUMENT_MAP.each do |key, value|
117
- view = view.send(key, arguments[value]) if arguments[value]
112
+ collection.find(filter, options).to_a
113
+ end
114
+
115
+ def options
116
+ ARGUMENT_MAP.reduce({}) do |opts, (key, value)|
117
+ arguments[value] ? opts.merge!(key => arguments[value]) : opts
118
118
  end
119
- view.to_a
120
119
  end
121
120
 
122
121
  def batch_size
@@ -42,7 +42,9 @@ module Mongo
42
42
  # @since 2.0.0
43
43
  ARGUMENT_MAP = {
44
44
  :sort => 'sort',
45
- :projection => 'projection'
45
+ :projection => 'projection',
46
+ :return_document => 'returnDocument',
47
+ :upsert => 'upsert'
46
48
  }
47
49
 
48
50
  # Operations that need a check if results on < 2.6 will match.
@@ -111,12 +113,12 @@ module Mongo
111
113
  private
112
114
 
113
115
  def delete_many(collection)
114
- result = collection.find(filter).delete_many
116
+ result = collection.delete_many(filter)
115
117
  { 'deletedCount' => result.deleted_count }
116
118
  end
117
119
 
118
120
  def delete_one(collection)
119
- result = collection.find(filter).delete_one
121
+ result = collection.delete_one(filter)
120
122
  { 'deletedCount' => result.deleted_count }
121
123
  end
122
124
 
@@ -137,48 +139,50 @@ module Mongo
137
139
  end
138
140
 
139
141
  def replace_one(collection)
140
- result = collection.find(filter).replace_one(replacement, upsert: upsert)
142
+ result = collection.replace_one(filter, replacement, options)
141
143
  update_return_doc(result)
142
144
  end
143
145
 
144
146
  def update_many(collection)
145
- result = collection.find(filter).update_many(update, upsert: upsert)
147
+ result = collection.update_many(filter, update, options)
146
148
  update_return_doc(result)
147
149
  end
148
150
 
149
151
  def update_one(collection)
150
- result = collection.find(filter).update_one(update, upsert: upsert)
152
+ result = collection.update_one(filter, update, options)
151
153
  update_return_doc(result)
152
154
  end
153
155
 
154
156
  def find_one_and_delete(collection)
155
- view = collection.find(filter)
156
- ARGUMENT_MAP.each do |key, value|
157
- view = view.send(key, arguments[value]) if arguments[value]
158
- end
159
- view.find_one_and_delete
157
+ collection.find_one_and_delete(filter, options)
160
158
  end
161
159
 
162
160
  def find_one_and_replace(collection)
163
- view = collection.find(filter)
164
- ARGUMENT_MAP.each do |key, value|
165
- view = view.send(key, arguments[value]) if arguments[value]
166
- end
167
- view.find_one_and_replace(replacement, upsert: upsert, return_document: return_document)
161
+ collection.find_one_and_replace(filter, replacement, options)
168
162
  end
169
163
 
170
164
  def find_one_and_update(collection)
171
- view = collection.find(filter)
172
- ARGUMENT_MAP.each do |key, value|
173
- view = view.send(key, arguments[value]) if arguments[value]
165
+ collection.find_one_and_update(filter, update, options)
166
+ end
167
+
168
+ def options
169
+ ARGUMENT_MAP.reduce({}) do |opts, (key, value)|
170
+ arguments[value] ? opts.merge!(key => send(key)) : opts
174
171
  end
175
- view.find_one_and_update(update, upsert: upsert, return_document: return_document)
176
172
  end
177
173
 
178
174
  def replacement
179
175
  arguments['replacement']
180
176
  end
181
177
 
178
+ def sort
179
+ arguments['sort']
180
+ end
181
+
182
+ def projection
183
+ arguments['projection']
184
+ end
185
+
182
186
  def documents
183
187
  arguments['documents']
184
188
  end
@@ -0,0 +1,45 @@
1
+ description: "New primary with equal electionId"
2
+
3
+ uri: "mongodb://a/?replicaSet=rs"
4
+
5
+ phases: [
6
+
7
+ # A and B claim to be primaries, with equal electionIds.
8
+ {
9
+ responses: [
10
+ ["a:27017", {
11
+ ok: 1,
12
+ ismaster: true,
13
+ hosts: ["a:27017", "b:27017"],
14
+ setName: "rs",
15
+ electionId: {"$oid": "000000000000000000000001"}
16
+ }],
17
+ ["b:27017", {
18
+ ok: 1,
19
+ ismaster: true,
20
+ hosts: ["a:27017", "b:27017"],
21
+ setName: "rs",
22
+ electionId: {"$oid": "000000000000000000000001"}
23
+ }]
24
+ ],
25
+
26
+ # No choice but to believe the latter response.
27
+ outcome: {
28
+ servers: {
29
+ "a:27017": {
30
+ type: "Unknown",
31
+ setName: ,
32
+ electionId: ,
33
+ },
34
+ "b:27017": {
35
+ type: "RSPrimary",
36
+ setName: "rs",
37
+ electionId: {"$oid": "000000000000000000000001"}
38
+ }
39
+ },
40
+ topologyType: "ReplicaSetWithPrimary",
41
+ setName: "rs",
42
+ maxElectionId: {"$oid": "000000000000000000000001"}
43
+ }
44
+ }
45
+ ]
@@ -0,0 +1,98 @@
1
+ description: "New primary with greater electionId"
2
+
3
+ uri: "mongodb://a/?replicaSet=rs"
4
+
5
+ phases: [
6
+
7
+ # Primary A is discovered and tells us about B.
8
+ {
9
+ responses: [
10
+ ["a:27017", {
11
+ ok: 1,
12
+ ismaster: true,
13
+ hosts: ["a:27017", "b:27017"],
14
+ setName: "rs",
15
+ electionId: {"$oid": "000000000000000000000001"}
16
+ }]
17
+ ],
18
+
19
+ outcome: {
20
+ servers: {
21
+ "a:27017": {
22
+ type: "RSPrimary",
23
+ setName: "rs",
24
+ electionId: {"$oid": "000000000000000000000001"}
25
+ },
26
+ "b:27017": {
27
+ type: "Unknown",
28
+ setName: ,
29
+ electionId:
30
+ }
31
+ },
32
+ topologyType: "ReplicaSetWithPrimary",
33
+ setName: "rs",
34
+ maxElectionId: {"$oid": "000000000000000000000001"}
35
+ }
36
+ },
37
+
38
+ # B is elected.
39
+ {
40
+ responses: [
41
+ ["b:27017", {
42
+ ok: 1,
43
+ ismaster: true,
44
+ hosts: ["a:27017", "b:27017"],
45
+ setName: "rs",
46
+ electionId: {"$oid": "000000000000000000000002"}
47
+ }]
48
+ ],
49
+
50
+ outcome: {
51
+ servers: {
52
+ "a:27017": {
53
+ type: "Unknown",
54
+ setName: ,
55
+ electionId:
56
+ },
57
+ "b:27017": {
58
+ type: "RSPrimary",
59
+ setName: "rs",
60
+ electionId: {"$oid": "000000000000000000000002"}
61
+ }
62
+ },
63
+ topologyType: "ReplicaSetWithPrimary",
64
+ setName: "rs",
65
+ maxElectionId: {"$oid": "000000000000000000000002"}
66
+ }
67
+ },
68
+
69
+ # A still claims to be primary but it's ignored.
70
+ {
71
+ responses: [
72
+ ["a:27017", {
73
+ ok: 1,
74
+ ismaster: true,
75
+ hosts: ["a:27017", "b:27017"],
76
+ setName: "rs",
77
+ electionId: {"$oid": "000000000000000000000001"}
78
+ }]
79
+ ],
80
+ outcome: {
81
+ servers: {
82
+ "a:27017": {
83
+ type: "Unknown",
84
+ setName: ,
85
+ electionId:
86
+ },
87
+ "b:27017": {
88
+ type: "RSPrimary",
89
+ setName: "rs",
90
+ electionId: {"$oid": "000000000000000000000002"}
91
+ }
92
+ },
93
+ topologyType: "ReplicaSetWithPrimary",
94
+ setName: "rs",
95
+ maxElectionId: {"$oid": "000000000000000000000002"}
96
+ }
97
+ }
98
+ ]