(작동하지 않습니다.) 당신은 커서를 변환하거나해야합니다
http://php.net/manual/en/class.mongocursor.php
PHP는 배열에 ...
는
<?
// Connect to Mongo and set DB and Collection
$mongo = new Mongo();
$db = $mongo->twitter;
$collection = $db->tweets;
// Return a cursor of tweets from MongoDB
$cursor = $collection->find();
// Convert cursor to an array
$array = iterator_to_array($cursor);
// Loop and print out tweets ...
foreach ($array as $value) {
echo "<p>" . $value[text];
echo " @ <b><i>" . $value[created_at] . "</i></b>";
}
?>
은 또는 ...에서 MongoCursor을 반환하지 않습니다하는 대신) findOne를 (사용 당신은 단지 싶다면 하나의 문서를 가져 와서 JSON으로 응용 프로그램에 반환하면 다음과 같이 간단하게 처리 할 수 있습니다 (요청한대로 JSON 및 print_r을 수행하는 방법을 보여줍니다).
자세한 내용은이 기사를 참조하십시오.
당신이 방법으로 몽고를 조회 할 수 있습니다 쉘을 사용
http://learnmongo.com/posts/mongodb-php-install-and-connect/
http://learnmongo.com/posts/mongodb-php-twitter-part-1/
<?php
$connection = new Mongo();
$db = $connection->test;
$collection = $db->phptest;
$obj = $collection->findOne();
echo "<h1>Hello " . $obj["hello"] . "!</h1>";
echo "<h2>Show result as an array:</h2>";
echo "<pre>";
print_r($obj);
echo "</pre>";
echo "<h2>Show result as JSON:</h2>";
echo "<pre>";
echo json_encode($obj);
echo "</pre>";
?>
https://gist.github.com/a1cceb8d4ec8ced1fbdb - 지금 어떻게하고 있니? 그냥 지저분 해 보인다. \ –