MongoDB\Driver\Cursor::getServer

(mongodb >=1.0.0)

MongoDB\Driver\Cursor::getServerReturns the server associated with this cursor

说明

final public MongoDB\Driver\Cursor::getServer ( void ) : MongoDB\Driver\Server

Returns the MongoDB\Driver\Server associated with this cursor. This is the server that executed the MongoDB\Driver\Query or MongoDB\Driver\Command.

参数

此函数没有参数。

返回值

Returns the MongoDB\Driver\Server associated with this cursor.

错误/异常

范例

Example #1 MongoDB\Driver\Cursor::getServer() example

<?php

$manager 
= new MongoDB\Driver\Manager("mongodb://localhost:27017");
$query = new MongoDB\Driver\Query([]);

$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert(['x' => 1]);
$manager->executeBulkWrite('db.collection'$bulk);

$cursor $manager->executeQuery('db.collection'$query);
var_dump($cursor->getServer());

?>

以上例程的输出类似于:

object(MongoDB\Driver\Server)#5 (10) {
  ["host"]=>
  string(9) "localhost"
  ["port"]=>
  int(27017)
  ["type"]=>
  int(1)
  ["is_primary"]=>
  bool(false)
  ["is_secondary"]=>
  bool(false)
  ["is_arbiter"]=>
  bool(false)
  ["is_hidden"]=>
  bool(false)
  ["is_passive"]=>
  bool(false)
  ["last_is_master"]=>
  array(8) {
    ["ismaster"]=>
    bool(true)
    ["maxBsonObjectSize"]=>
    int(16777216)
    ["maxMessageSizeBytes"]=>
    int(48000000)
    ["maxWriteBatchSize"]=>
    int(1000)
    ["localTime"]=>
    object(MongoDB\BSON\UTCDateTime)#6 (1) {
      ["milliseconds"]=>
      int(1446505367907)
    }
    ["maxWireVersion"]=>
    int(3)
    ["minWireVersion"]=>
    int(0)
    ["ok"]=>
    float(1)
  }
  ["round_trip_time"]=>
  int(584)
}
相关文章
php mongodb driver the mongodb driver server classphp mongodb driver cursor returns the id for this cursorphp mongodb driver cursor returns the server associated with this cursorphp mongodb driver cursor returns an array containing all results for this cursorphp mongodb driver cursorid string representation of the cursor idphp mongodb driver monitoring commandfailedevent returns the exception associated with the failed commandphp mongodb driver monitoring commandfailedevent returns the server on which the command was executedphp mongodb driver monitoring commandstartedevent returns the server on which the command was executedphp mongodb driver monitoring commandsucceededevent returns the command s operation idphp mongodb driver monitoring commandsucceededevent returns the server on which the command was executedphp mongodb driver exception runtimeexception returns whether an error label is associated with an exceptionphp mongodb driver server execute one or more write operations on this serverphp mongodb driver server returns the hostname of this serverphp mongodb driver server returns an array of information about this serverphp mongodb driver server returns the latency of this serverphp mongodb driver server returns the port on which this server is listeningphp mongodb driver server returns an array of tags describing this server in a replica setphp mongodb driver server returns an integer denoting the type of this serverphp mongodb driver server checks if this server is a secondary member of a replica setphp mongodb driver writeresult returns the server associated with this write result
关注编程学问公众号