Skip to content

Commit 85c13bd

Browse files
committed
Fix "undefined index primary" when no primary is available
1 parent 907e205 commit 85c13bd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/main/php/com/mongodb/io/Protocol.class.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ public function candidates($rp) {
178178
* @return void
179179
*/
180180
public function useCluster($server) {
181-
$this->nodes= ['primary' => $server['primary'] ?? key($this->conn), 'secondary' => []];
181+
$primary= $server['primary'] ?? key($this->conn);
182+
$this->nodes= ['primary' => $primary, 'secondary' => []];
182183
foreach ($server['hosts'] ?? [] as $host) {
183-
if ($server['primary'] !== $host) $this->nodes['secondary'][]= $host;
184+
if ($primary !== $host) $this->nodes['secondary'][]= $host;
184185
}
185186
shuffle($this->nodes['secondary']);
186187
}

0 commit comments

Comments
 (0)