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.
반환 값
값이 반환되지 않습니다.
오류/예외
- 인수 구문 분석 오류에 대해 MongoDB\Driver\Exception\InvalidArgumentException을 던집니다.
커서를 반복할 때 잘못된 유형 맵 구성으로 인해 다음 예외가 발생할 수도 있습니다.
- 유형 맵의 클래스를 인스턴스화할 수 없거나 MongoDB\BSON\Unserializable을 구현하지 않는 경우 MongoDB\Driver\Exception\InvalidArgumentException을 던집니다.
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) }