错误:致命错误:未捕获的异常' MongoException'

时间:2015-04-07 16:41:11

标签: php mongodb

谁可以帮助我,当我想要转到文件article.php时,我有这个错误:

致命错误:未捕获的异常' MongoException'消息'无效的对象ID'在/Applications/XAMPP/xamppfiles/htdocs/www/Site/Test/article1.php:14堆栈跟踪:#0 /Applications/XAMPP/xamppfiles/htdocs/www/Site/Test/article1.php(14):MongoId- > __ construct('
注意......')#1 {main}抛出

文件article1.php的开头

<?php



      $id = $_GET['id'];
      try {
        $connection = new MongoClient();
        $database   = $connection->selectDB('test');
        $collection = $database->selectCollection('articles');
      } catch(MongoConnectionException $e) {
        die("Failed to connect to database ".$e->getMessage());
      }
      $article = $collection->findOne(array('_id' => new MongoId($id)));


?>

1 个答案:

答案 0 :(得分:1)

您只是捕获类型&#34; MongoConnectionException&#34;的例外。而代码抛出更通用的&#34; MongoException&#34;

Catch(MongoException $e)