I am trying to fetch all data from my collection in mongodb using the following code
public function fetch_employee_list()
{
$m = new MongoClient();
$db = $m->selectDB('fleet');
$collection = new MongoCollection($db, 'employee');
// $name = array('Type' => 'name');
$cursor = $collection->find();
echo "<pre>";
print_r($cursor);
exit;
}
and the result I am getting is "MongoCursor Object()
" but when i use
$cursor = $collection->findOne();
it gives me one result as array. what I did wrong?
You need to do something like
$cursor = $collection->find();
foreach ($cursor as $obj) {
echo $obj . "\n";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.