连接到mongodb时出错500

时间:2016-12-07 11:40:49

标签: php

我有这个代码,我用来尝试连接到ubuntu 16服务器上的mongodb

<?php
$uri = "mongodb://admin:admin123@localhost:27017/mydb";

   // connect to mongodb
   $m = new MongoClient($uri);
   echo "Connection to database successfully";

   // select a database
   $db = $m->mydb;
   echo "Database mydb selected";
   $collection = $db->mycol;
   echo "Collection selected succsessfully";

   $document = array( 
      "title" => "MongoDB", 
      "description" => "database", 
      "likes" => 100,
      "url" => "http://www.tutorialspoint.com/mongodb/",
      "by", "tutorials point"
   );

   $collection->insert($document);
   echo "Document inserted successfully";
?>

每次我运行脚本时都会收到错误

The 004.000.0.000 page isn’t working

004.000.0.000 is currently unable to handle this request.

HTTP ERROR 500

为什么我无法连接数据库?

1 个答案:

答案 0 :(得分:0)

检查您的php日志,您可能会看到更具体的错误。还要通过从命令行连接来验证mongo是否正在运行。