我使用PHP 5.6和Mongo 3.4(Atlas)。我想将读取密集型查询路由到辅助节点。
示例:
$m = new MongoClient();
echo "Connection to database successfully";
// select a database
$db = $m->mydb;
// collection selected
$collection = $db->mycol;
echo "Collection selected succsessfully";
// all transactionos for the web
$cursor = $collection->find();
// a read intensive report generation
if ( need to generate a report )
$m->mydb->setReadPreference( Mongo::RP_SECONDARY_PREFERRED );
所以当我这样做时:
$cursor2 = $collection->find();
设置readPreference后
数据来自次要偏好还是我必须再次执行以下操作?
$collection = $db->mycol;
如何测试mongo的哪个节点执行了查询?