Update MongoDB Handling #670

wants to merge 3 commits into


None yet

5 participants

  • Allows specifying a read preference, and tags
  • Updates docs to suggest using a string to indicate which replica set should be used
  • Continues to use connect -> true option as an option. This was incorrectly marked as deprecated in one of the driver releases, I've confirmed with Derick Rethans that this will remain (though it is also the default setting).

Unit tests are on you :)

preinheimer added some commits Oct 28, 2012
@preinheimer preinheimer - Switch from using depricated connect = true option to manually inv…
…oking connect()

 - Provide configuration ability for readPrefernce options
@preinheimer preinheimer - Updating handling to allow specifying replica set as a string, rat…
…her than boolean (old style)

 - Handling specifying read preferenceswith tags
@preinheimer preinheimer - Push the safe value into configuration so it can be set once when the
   connnection is created

Just added an option that allows developers to specify safe = true as a default when configuring their connection. This is a sensible default for a lot of apps, so setting once would be nifty.

Union of RAD member

👍 for safe = true as a default, a much saner default for most apps.


While I'm certainly setting safe = true in my connection settings, I didn't feel like I should make that level of a change to the driver by changing that with my patch.

@nateabele nateabele commented on the diff Nov 5, 2012
if ($this->connection = $this->server->{$cfg['database']}) {
$this->_isConnected = true;
+ if ($prefs = $cfg['readPreference']) {
+ //If $prefs is an array use as is, otherwise (as is the case when only a read preference
nateabele Nov 5, 2012 Union of RAD member

K, minor nitpick: per the coding standard, we don't do inline comments. Other than that, this looks perfect, and I'll merge immediately.

Union of RAD member

@preinheimer Good call on adding 'safe' as a connection-wide option. I'll take care of the unit test once it's on dev. Just do me a favor and strip out that inline comment (and squash the commits if it's not too much trouble — if it is, don't worry about it), and I'll get it merged, both post-haste and forthwith.


(originally from Issue #698, closed to move discussion here)

There is a shift coming in the MongoDB Native Driver for PHP:

Specifically as of version 1.3.0, Mongo will be deprecated and replaced with MongoClient

There's a few new features, that I'm aware of:

  • Write Concern, which will replace safe and fsync.
    • array("w" => 3)
  • Read Preference which provides better control than setSlaveOkay over replica sets.
    • array("readPreference" => MongoClient::RP_PRIMARY_PREFERRED)

(see: http://us2.php.net/manual/en/mongoclient.construct.php for reference)

Union of RAD member

I believe we're already patched for readPreference.

@jails jails added a commit that closed this pull request Dec 12, 2012
@jails jails Patch for `readPreference` close #670 and #698 42d5474
@jails jails closed this in 42d5474 Dec 12, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment