Hannes Magnusson <notifications@github.com> wrote:

> > +	zend_bool     slave_okay = 1;
> > +
> > +	PREITERATION_SETUP;
> > +
> > +	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b",
> &slave_okay) == FAILURE) {
> > +		return;
> > +	}
> > +
> > +	set_cursor_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU,
> CURSOR_FLAG_SLAVE_OKAY, slave_okay);
> > +
> > +	/* SlaveOkay implicitly should set the read preference to
> > +	 * RP_SECONDARY_PREFERRED, but only, if it's still the default of
> > +	 * RP_PRIMARY */
> > +	if (slave_okay && cursor->read_pref.type == MONGO_RP_PRIMARY) {
> > +		cursor->read_pref.type = MONGO_RP_SECONDARY_PREFERRED;
> > +	}
> 
> How does $cursor->slaveOkay(true); $cursor->slaveOkay(false) work? It
> doesn't seem to reset the RP to PRIMARY, and later in do query it sees
> that the read preference is still secondary preferred and will set the
> slaveOkay cursor option?

Interesting indeed. The test shows it works but I'll check it.