protected function setReadPreferenceToPrimary()
    {
        // Set db preference
        /** @var ReadPreference $dbReadPref */
        $dbReadPref = $this->getDatabase()->__debugInfo()['readPreference'];

        $dbPref = $dbReadPref->getMode();
        $dbTagsets = $dbReadPref->getTagsets();

        $this->originalDbReadPreference = $this->db->__debugInfo()['readPreference']->getMode();
        if ($dbPref !== ReadPreference::RP_PRIMARY) {
            $this->db = $this->db->withOptions(array('readPreference' => new ReadPreference(ReadPreference::RP_PRIMARY, $dbTagsets)));
        }

        /** @var ReadPreference $collReadPref */
        $collReadPref = $this->getCollection()->__debugInfo()['readPreference'];
        $collPref = $collReadPref->getMode();
        $collTagsets = $collReadPref->getTagsets();

        // Set collection preference
        $this->originalCollectionReadPreference = $collPref;
        if ($collPref !== ReadPreference::RP_PRIMARY) {
            $this->collection = $this->collection->withOptions(array('readPreference' => new ReadPreference(ReadPreference::RP_PRIMARY, $collTagsets)));
        }
    }
protected function setReadPreferenceToPrimary()
    {
        // Set db preference
        /** @var ReadPreference $dbReadPref */
        $dbReadPref = $this->getDatabase()->__debugInfo()['readPreference'];

        $dbPref = $dbReadPref->getMode();
        $dbTagsets = $dbReadPref->getTagsets();

        $this->originalDbReadPreference = $this->db->__debugInfo()['readPreference']->getMode();
        if ($dbPref !== ReadPreference::RP_PRIMARY) {
            $this->db = $this->db->withOptions(array('readPreference' => new ReadPreference(ReadPreference::RP_PRIMARY, $dbTagsets)));
        }

        /** @var ReadPreference $collReadPref */
        $collReadPref = $this->getCollection()->__debugInfo()['readPreference'];
        $collPref = $collReadPref->getMode();
        $collTagsets = $collReadPref->getTagsets();

        // Set collection preference
        $this->originalCollectionReadPreference = $collPref;
        if ($collPref !== ReadPreference::RP_PRIMARY) {
            $this->collection = $this->collection->withOptions(array('readPreference' => new ReadPreference(ReadPreference::RP_PRIMARY, $collTagsets)));
        }
    }
protected function setReadPreferenceToPrimary ( ) { // Set db preference /** @var ReadPreference $dbReadPref */ $ dbReadPref = $ this -> getDatabase ( ) -> __debugInfo ( ) [ 'readPreference' ] ; $ dbPref = $ dbReadPref -> getMode ( ) ; $ dbTagsets = $ dbReadPref -> getTagsets ( ) ; $ this -> originalDbReadPreference = $ this -> db -> __debugInfo ( ) [ 'readPreference' ] -> getMode ( ) ; if ( $ dbPref !== ReadPreference :: RP_PRIMARY ) { $ this -> db = $ this -> db -> withOptions ( array ( 'readPreference' => new ReadPreference ( ReadPreference :: RP_PRIMARY , $ dbTagsets ) ) ) ; } /** @var ReadPreference $collReadPref */ $ collReadPref = $ this -> getCollection ( ) -> __debugInfo ( ) [ 'readPreference' ] ; $ collPref = $ collReadPref -> getMode ( ) ; $ collTagsets = $ collReadPref -> getTagsets ( ) ; // Set collection preference $ this -> originalCollectionReadPreference = $ collPref ; if ( $ collPref !== ReadPreference :: RP_PRIMARY ) { $ this -> collection = $ this -> collection -> withOptions ( array ( 'readPreference' => new ReadPreference ( ReadPreference :: RP_PRIMARY , $ collTagsets ) ) ) ; } }
Change the read preferences to RP_PRIMARY
Used for a write operation
@todo When there is a getReadPreference function available in the PHP Mongo library (or the read
preference is readable) we should use that instead of the debugInfo function we're using here.
Change the read preferences to RP_PRIMARY Used for a write operation