diff --git a/src/main/php/com/mongodb/io/Commands.class.php b/src/main/php/com/mongodb/io/Commands.class.php index 787e06a..c68e61e 100755 --- a/src/main/php/com/mongodb/io/Commands.class.php +++ b/src/main/php/com/mongodb/io/Commands.class.php @@ -23,7 +23,7 @@ private function __construct($proto, $conn) { /** Creates an instance for reading */ public static function reading(Protocol $proto): self { return new self($proto, $proto->establish( - $proto->candidates($proto->readPreference['mode']), + $proto->candidates($proto->readPreference), 'reading with '.$proto->readPreference['mode'] )); } diff --git a/src/main/php/com/mongodb/io/Protocol.class.php b/src/main/php/com/mongodb/io/Protocol.class.php index a23ff0a..3a05ea9 100755 --- a/src/main/php/com/mongodb/io/Protocol.class.php +++ b/src/main/php/com/mongodb/io/Protocol.class.php @@ -141,20 +141,20 @@ public function connect() { * * @see https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.rst#read-preference * @see https://docs.mongodb.com/manual/core/read-preference-mechanics/ - * @param string $rp + * @param [:var] $rp * @return string[] * @throws lang.IllegalArgumentException */ public function candidates($rp) { - if ('primary' === $rp) { + if ('primary' === $rp['mode']) { return [$this->nodes['primary']]; - } else if ('secondary' === $rp) { + } else if ('secondary' === $rp['mode']) { return $this->nodes['secondary']; - } else if ('primaryPreferred' === $rp) { + } else if ('primaryPreferred' === $rp['mode']) { return array_merge([$this->nodes['primary']], $this->nodes['secondary']); - } else if ('secondaryPreferred' === $rp) { + } else if ('secondaryPreferred' === $rp['mode']) { return array_merge($this->nodes['secondary'], [$this->nodes['primary']]); - } else if ('nearest' === $rp) { // Prefer to stay on already open connections + } else if ('nearest' === $rp['mode']) { // Prefer to stay on already open connections $connected= null; foreach ($this->conn as $id => $conn) { if (null === $conn->server) continue; @@ -229,7 +229,7 @@ public function read(array $options, $sections) { } $rp= $sections['$readPreference'] ?? $this->readPreference; - return $this->establish($this->candidates($rp['mode']), 'reading with '.$rp['mode']) + return $this->establish($this->candidates($rp), 'reading with '.$rp['mode']) ->message($sections, $rp) ; }