2017-03-29 1 views
0

정의되지 않은 메서드 MongoCursor :: toArray()에 전화를 걸어이를 위해 나는이 오류가치명적인 오류 : 나는 내가 커서 결과를 볼 수 있도록 배열에 커서를 변환 할

"치명적인 오류를 표시하여 MongoDB의 toArray를 사용했을 때

$getting_started_collection = $this->getServiceLocator()->get('Common\Collection\ResourcesGettingStarted'); 
$criteria = array(
    '$or' => array(
     array('affiliate_type' => 'cpl_cpm'), 
     array('affiliate_type' => 'cpl') 
    ) 
); 
$columns = array(
    '_id' => true, 
    'title' => true, 
    'description' => true, 
    'logo' => true, 
    'pdf' => true 
); 
$cursor = $getting_started_collection->fetchAll($criteria, $columns, true); 
$data_array = $cursor->toArray(); 
echo("<pre>"); 
print_r($data_array); 
die(); 

내가 https://docs.mongodb.com/manual/reference/method/cursor.toArray/을 사용하는 방법 : 정의되지 않은 메서드 MongoCursor ::으로써 toArray()를 호출 "여기

내 코드?

답변

1

MongoCursor 클래스에는 toArray이라는 메서드가 없기 때문입니다. 다음은 사용 가능한 모든 방법 목록입니다 (MongoCursor).
당신은 설명서에 Example #1에로 iterator_to_array()을 사용해야합니다

<?php 

$cursor = $collection->find(); 
var_dump(iterator_to_array($cursor)); 

?> 

출처 : http://php.net/manual/en/class.mongocursor.php 당신의 예에서

:

$cursor = $getting_started_collection->fetchAll($criteria, $columns, true); 
$data_array = iterator_to_array($cursor); 
echo("<pre>"); 
print_r($data_array); 
die(); 
+0

이 볼 수 https://docs.mongodb.com/ 수동/참조/방법/cursor.toArray / –

관련 문제