无法通过 PHP 连接到 MongoDB
我只是想看看 Mongo-DB。但我就是不让它运行。我已经使用 PECL 安装了它,我的 phpinfo()
告诉我扩展已加载,但是当我尝试与
$mongo = new Mongo();
建立连接时>
我明白了:
致命错误:未捕获异常“MongoConnectionException” 消息“:传输端点未连接”
有人有同样的问题吗? ...或者对此有什么想法吗?
I just wanted to take a look at Mongo-DB. But i just don't get it running. I've installed it with PECL and my phpinfo()
tells me that the extension is loaded, but when i try to get a connection with
$mongo = new Mongo();
I get this:
Fatal error: Uncaught exception 'MongoConnectionException' with
message ': Transport endpoint is not connected'
Anybody have the same Problem? ... Or any Idea on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
请不要误解这一点,但是你真的让服务器运行了吗?只是看起来您的错误与连接失败有关,并且您没有提及服务器或它所在的位置(例如默认端口上的本地主机)
Please don't take this the wrong way, but have you actually got the server running? Only it looks like your error relates to a failure to connect and you've made no mention of the server or where it is located (localhost on the default port for example)
如果过时的锁定文件仍然存在,任何服务器启动方法(例如“/etc/init.d/mongodb start”或“service start mongodb”)都将失败。在 Ubuntu/Debian 中,这是 /var/lib/mongodb/mongod.lock。查找并删除它,如果它存在并且似乎是旧的。
any server start method, such as "/etc/init.d/mongodb start" or "service start mongodb" will fail, if a stale lock file still exists. In Ubuntu/Debian this is /var/lib/mongodb/mongod.lock. Look for this and delte it, if it exists and seems to be an old one.
检查服务器是否正在运行..
/etc/init.d/mongodb start
然后转到
root@kannan-desktop:~# mongo
MongoDB shell 版本:1.6.3
连接到:测试
>
check out whether server is running or not..
/etc/init.d/mongodb start
then go to
root@kannan-desktop:~# mongo
MongoDB shell version: 1.6.3
connecting to: test
>
如果是新安装,请不要忘记更改
mongod.conf
中的 IP。Don't forget to change the IP in your
mongod.conf
if it's a new installation.自定义字符串看起来像这样
custom string looks like that
首先通过以下命令更改默认数据库路径
$ sudo mkdir -p /data/db/
$ sudo chown
id -u
/data/db然后最后的命令是..
$ mongod --journal
在使用 mongoDB 之前不要关闭终端
它对我有用...
First Change the Default db path by following command
$ sudo mkdir -p /data/db/
$ sudo chown
id -u
/data/dband then the final command is..
$ mongod --journal
Do not close terminal until you are working with mongoDB
It works for me...
只需在终端中写入
mongod
即可正常工作just write
mongod
in your terminal and will work well