/** * Wrapper method for MongoCursor::setReadPreference(). * * @see \Doctrine\MongoDB\Cursor::setReadPreference() * @see http://php.net/manual/en/mongocursor.setreadpreference.php * @param string $readPreference * @param array $tags * @return self */ public function setReadPreference($readPreference, array $tags = null) { $this->baseCursor->setReadPreference($readPreference, $tags); $this->unitOfWorkHints[Query::HINT_READ_PREFERENCE] = $readPreference; $this->unitOfWorkHints[Query::HINT_READ_PREFERENCE_TAGS] = $tags; return $this; }
/** * Prepare the Cursor returned by {@link Query::execute()}. * * This method will apply cursor options present in the query structure * array. The Cursor may also be wrapped with an EagerCursor. * * @param Cursor $cursor * @return CursorInterface */ protected function prepareCursor(Cursor $cursor) { /* Note: if this cursor resulted from a mapReduce command, applying the * read preference may be undesirable. Results would have been written * to the primary and replication may still be in progress. */ if (isset($this->query['readPreference'])) { $cursor->setReadPreference($this->query['readPreference'], $this->query['readPreferenceTags']); } foreach ($this->getQueryOptions('hint', 'immortal', 'limit', 'skip', 'slaveOkay', 'sort', 'maxTimeMS') as $key => $value) { $cursor->{$key}($value); } if (!empty($this->query['snapshot'])) { $cursor->snapshot(); } if (!empty($this->query['eagerCursor'])) { $cursor = new EagerCursor($cursor); } if (isset($this->query['useIdentifierKeys'])) { $cursor->setUseIdentifierKeys($this->query['useIdentifierKeys']); } return $cursor; }