php - How to force slaveOK = true for all MongoDB connections -


so i've inherited large body of php code, , less optimal, here main problems:

  • it has wrapper class mongo operations, such returning database objects, collection objects, etc...but wrapper class not used in great deal of places.
  • in many places in code, there extensive use of deprecated class 'mongo' opposed wrapper class.
  • the mongo cluster running on 1.8, not option upgrade.

my task configure replication cluster , load balance reads across slaves. put 'setslaveokay(true)' code in wrapper class, ideally should have been needed...however direct access 'mongo' , other classes in many places in code not have correct slaveokay values set. bad code appears in many places, inhibitive go in , fix every occurrence.

so ideally i'm looking either:

  • a way configure slave node slaveokay=true implied connections across platforms.
  • a static property or function mongo class cause subsequent objects have slaveokay=true

i understand people here have strong inclination give solutions done "the right way", in case, suggestions "upgrade newest mongo , use read preferences" or "create wrapper class ..." not useful. inherited code, inherited mongo installation. need quick , dirty fix won't break existing projects...going code , changing 500 invocations of 'mongo' class use wrapper not option - introduce many potential bugs in code - , there no guarantee other coders on team stop circumventing wrapper class.

thanks time.

you can update latest php driver , use read preferences. has nothing server side, unless using sharding, in case need mongos comes mongodb 2.4+. if you're not using sharding, don't need 2.4 cluster read preferences handled on client side.

i guess have connection string configured somewhere? if that's case, can add ?readpreference=secondaryprefered.


Comments