PHP Conference Kansai 2025

MongoDB\Driver\Cursor::getServer

(mongodb >=1.0.0)

MongoDB\Driver\Cursor::getServerDevuelve el servidor asociado a este cursor

Descripción

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

Devuelve el MongoDB\Driver\Server asociado a este cursor. Se trata del servidor que ha ejecutado la MongoDB\Driver\Query o MongoDB\Driver\Command.

Parámetros

Esta función no tiene parámetros.

Valores devueltos

Devuelve el MongoDB\Driver\Server asociado a este cursor.

Errores/Excepciones

Ejemplos

Ejemplo #1 Ejemplo con MongoDB\Driver\Cursor::getServer()

<?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());

?>

El resultado del ejemplo sería algo similar a:

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_hello_response"]=>
  array(8) {
    ["isWritablePrimary"]=>
    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)
}

Ver también

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top