MongoDB\Driver\Cursor::toArray

mongodb >=1.0.0)

MongoDB\Driver\Cursor::toArray — 이 커서에 대한 모든 결과를 포함하는 배열을 반환합니다.


설명

final public MongoDB\Driver\Cursor::toArray(): array

커서를 반복하고 결과를 배열로 반환합니다. MongoDB\Driver\Cursor::setTypeMap()은 문서가 PHP 값으로 직렬화 해제되는 방법을 제어하는 ​​데 사용할 수 있습니다.


매개변수

이 함수에는 매개변수가 없습니다.


반환 값

이 커서에 대한 모든 결과를 포함하는 배열을 반환합니다.


오류/예외


Examples

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

                  
<?php

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

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

$query = new MongoDB\Driver\Query([]);
$cursor = $manager->executeQuery('db.collection', $query);

var_dump($cursor->toArray());

?>
                  
                

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

array(3) {
  [0]=>
  object(stdClass)#6 (2) {
    ["_id"]=>
    object(MongoDB\BSON\ObjectId)#5 (1) {
      ["oid"]=>
      string(24) "564259a96118fd40b41bcf61"
    }
    ["x"]=>
    int(1)
  }
  [1]=>
  object(stdClass)#8 (2) {
    ["_id"]=>
    object(MongoDB\BSON\ObjectId)#7 (1) {
      ["oid"]=>
      string(24) "564259a96118fd40b41bcf62"
    }
    ["x"]=>
    int(2)
  }
  [2]=>
  object(stdClass)#10 (2) {
    ["_id"]=>
    object(MongoDB\BSON\ObjectId)#9 (1) {
      ["oid"]=>
      string(24) "564259a96118fd40b41bcf63"
    }
    ["x"]=>
    int(3)
  }
}
                

기타