PHP动态更改mongo读取首选项

时间:2018-06-12 07:01:19

标签: php mongodb read-replication

我使用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的哪个节点执行了查询?

0 个答案:

没有答案