[英]fetch all data from mongodb collection
I am trying to fetch all data from my collection in mongodb using the following code 我正在尝试使用以下代码从mongodb中的集合中获取所有数据
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 而我得到的结果是“ MongoCursor Object()
”,但是当我使用
$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";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.