MongoDB\Driver\Cursor::setTypeMap

mongodb >=1.0.0)

MongoDB\Driver\Cursor::setTypeMap — BSON 직렬화 해제에 사용할 유형 맵을 설정합니다.


설명

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

BSON 결과를 PHP 값으로 직렬화 해제할 때 사용할 유형 맵 구성을 설정합니다.


매개변수

typeMap (array)
Type map configuration.

반환 값

값이 반환되지 않습니다.


오류/예외


Examples

예제 #1 MongoDB\Driver\Cursor::setTypeMap() 예제

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

?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

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

기타