简体   繁体   English

“致命错误:未捕获的异常'MongoConnectionException',消息为'无法连接至:/tmp/mongodb-27017.sock:0:连接被拒绝'”

[英]“Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: /tmp/mongodb-27017.sock:0: Connection refused''”

I have the following code: 我有以下代码:

$this->connection = new MongoClient($uri, $options);
$this->database = $database;

However, at line $this->connection I get: 但是,在$this->connection我得到:

Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: /tmp/mongodb-27017.sock:0: Connection refused' in...

If I output the following: 如果我输出以下内容:

var_dump($uri, $options); exit;

I get: 我得到:

string(33) "mongodb:///tmp/mongodb-27017.sock" array(1) { ["connect"]=> bool(true) } 

This is in my dev environment, I'm not using any username/password for Mongo as I can login to the Mongo shell with mongo reputation alone. 这是在我的开发环境中,我没有为Mongo使用任何用户名/密码,因为我可以仅凭mongo reputation登录到Mongo shell。 From there I can view collection and documents. 从那里我可以查看馆藏和文件。

Originally I was getting Permissions denied, but I changed the permissions of my dev /tmp/mongodb-27017.sock to 777. Now I get "connection refused". 最初,我的权限被拒绝,但是我将dev /tmp/mongodb-27017.sock的权限更改为777。现在,我收到“连接被拒绝”的信息。

Anyway below is the file from my ll /tmp/ dir: 无论如何,下面是我的ll /tmp/目录中的文件:

srwxrwxrwx  1 mongodb mongodb     0 Jan 28 07:47 mongodb-27017.sock=

Anyone know what the issue is, or how I can debug further? 任何人都知道问题是什么,或者我如何进一步调试? Thanks 谢谢

I would recommend in PHP connecting not to the socket which your process might not have permissions to access. 我建议在PHP中不要连接到您的进程可能没有访问权限的套接字。 If you modify the permission of the socket it's only temporary. 如果您修改套接字的权限,那只是暂时的。 When you stop the mongo db it will delete the socket, the next time you start it, the permissions will be back to whatever the default is (700 I think). 当您停止mongo db时,它将删除套接字,下次启动时,权限将恢复为默认值(我认为是700)。

Instead connect to the to the default port (27017) mongo opens on 127.0.0.1. 而是连接到默认端口(27017),然后在127.0.0.1上打开mongo。

Change you connection string in PHP to the following: 将PHP中的连接字符串更改为以下内容:

$uri = "mongodb://127.0.0.1";
$this->connection = new MongoClient($uri, $options);
$connection=  new \MongoClient("mongodb://localhost:27017");
return $this->db = $connection->selectDB($config['dbname']);

try this to connect local mongoDB. 试试这个连接本地mongoDB。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 消息“未能连接到:localhost:27017”的未捕获异常“ MongoConnectionException” - Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: localhost:27017 无法连接到MongoDB:无法连接到:333.33.333.333:27017:连接被拒绝 - Unable to connect to MongoDB: Failed to connect to: 333.33.333.333:27017: Connection refused Mongo DB显示错误致命错误:消息为“正在进行操作”的未捕获异常“ MongoConnectionException” - Mongo DB showing an error Fatal error: Uncaught exception 'MongoConnectionException' with message 'Operation now in progress' 无法连接到:localhost:27017:连接被拒绝 - Failed to connect to: localhost:27017: Connection refused 致命错误</ b>:未捕获的异常“异常”,消息“无法连接到api.twitter.com端口443:连接超时” - <b>Fatal error</b>: Uncaught exception 'Exception' with message 'Failed to connect to api.twitter.com port 443: Connection timed out' 无法连接到数据库:无法连接到:localhost:27017:连接被拒绝 - Unable to connect to Database: Failed to connect to: localhost:27017: Connection refused MongoDB + PHP:错误“无法连接到 127.0.0.1:27017” - MongoDB + PHP: Error “Failed to connect to 127.0.0.1:27017” PHP致命错误:带有消息&#39;cache_dir“/ tmp”的未捕获异常&#39;Zend_Cache_Exception&#39;必须是目录&#39; - PHP Fatal error: Uncaught exception 'Zend_Cache_Exception' with message 'cache_dir “/tmp” must be a directory' SMTP错误:无法连接到服务器:连接被拒绝(111)错误消息 - SMTP ERROR: Failed to connect to server: Connection refused (111) ERROR MESSAGE 消息为&#39;localhost:27017:DBClientBase :: findN的未捕获异常&#39;MongoCursorException&#39;:传输错误 - Uncaught exception 'MongoCursorException' with message 'localhost:27017: DBClientBase::findN: transport error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM