Catchable fatal error: Object of class MongoCursor could not be converted to string

Catchable fatal error: Object of class MongoCursor could not be converted to string

这是我在尝试查看从 MongoDB 到网页的数据时出现的错误。 在 Windows 中使用 Wamp:

Catchable fatal error: Object of class MongoCursor could not be converted to string

这是什么意思,我该怎么办?

我想出了删除错误检查代码的方法

<?php
// connect to mongodb
$m = new MongoClient();

$db = $m->local;    // select a database
$collection = $db->directors;  // select a collection (table in old DB)
$cursor = $collection->find(); // view all
foreach ($cursor as $doc)
{
    var_dump($doc);
}
?>

在上面的代码中,var_dump() 函数用于显示值或变量的数据类型,因此如果您使用它,在这种情况下,它还可以为您提供有关数据大小和长度的详细信息并显示结果。

此代码用于说明如何从 MongoDB 获取值并显示在 PHP 页面上。