Php/docs/mongocommandcursor.getreadpreference

提供:Dev Guides
< Php
移動先:案内検索

MongoCommandCursor::getReadPreference

(PECL mongo >=1.6.0)

MongoCommandCursor::getReadPreferenceGet the read preference for this command


説明

public MongoCommandCursor::getReadPreference ( ) : array

パラメータ

この関数にはパラメータはありません。


返り値

この関数は、優先読み込みに関する配列を返します。配列に含まれる内容は、type (優先読み込みモードを表す文字列。MongoClient の定数に対応)、そして tagsets (すべてのタグセット条件のリスト) です。タグセットを指定しなかった場合は、tagsets は存在しません。


例1 MongoCommandCursor::getReadPreference() return value example

<?php$m = new MongoClient('mongodb://rs1.example.com:27017', array('replicaSet' => 'myReplSetName'));$collection = $m->selectCollection('test', 'people');// If a MongoCommandCursor is constructed directly, it will inherit the read// preference of the MongoClient instance passed to its constructor; however,// MongoCollection::aggregateCursor() will have the MongoCommandCursor inherit// the collection's read preference.$collection->setReadPreference(MongoClient::RP_SECONDARY);$cursor = $collection->aggregateCursor( [    [ '$group' => [ '_id' => '$name', 'points' => [ '$sum' => '$points' ] ] ],    [ '$sort' => [ 'points' => -1 ] ],] );var_dump($cursor->getReadPreference());?>

上の例の出力は以下となります。


array(1) {
  ["type"]=>
  string(9) "secondary"
}

参考