Please wait while we load your page...
 

Announcements

PHP Manual :: MongoDB\Driver\Cursor::setTypeMap



MongoDB\Driver\Cursor::isDead || MongoDB\Driver\Cursor::toArray || MongoDB\Driver\Cursor || PHP Manual

(mongodb >=1.0.0)

MongoDB\Driver\Cursor::setTypeMapSets a type map to use for BSON unserialization

Description

final public void MongoDB\Driver\Cursor::setTypeMap ( array $typemap )

Sets the type map configuration to use when unserializing the BSON results into PHP values.

Parameters

typeMap (array)

Type map configuration.

Return Values

No value is returned.

Errors/Exceptions

Examples

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

<?php

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

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

$query = new MongoDB\Driver\Query(['_id' => $id]);
$cursor $manager->executeQuery('db.collection'$query);
$cursor->setTypeMap(['root' => 'array']);

foreach (
$cursor as $document) {
    
var_dump($document);
}

?>

The above example will output something similar to:

array(2) {
  ["_id"]=>
  object(MongoDB\BSON\ObjectID)#6 (1) {
    ["oid"]=>
    string(24) "56424fb76118fd3267180741"
  }
  ["x"]=>
  int(1)
}

See Also



MongoDB\Driver\Cursor::isDead || MongoDB\Driver\Cursor::toArray || MongoDB\Driver\Cursor || PHP Manual
Live Chat Not Available