Can't connect to MongoDB through PHP

2020-03-09 09:10发布

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?

7条回答
干净又极端
2楼-- · 2020-03-09 09:11

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 >

查看更多
Summer. ? 凉城
3楼-- · 2020-03-09 09:28

Don't forget to change the IP in your mongod.conf if it's a new installation.

查看更多
唯我独甜
4楼-- · 2020-03-09 09:29

custom string looks like that

mongodb://username:password@host:port/database
查看更多
够拽才男人
5楼-- · 2020-03-09 09:30

just write mongod in your terminal and will work well

查看更多
戒情不戒烟
6楼-- · 2020-03-09 09:31

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.

查看更多
Lonely孤独者°
7楼-- · 2020-03-09 09:31

First Change the Default db path by following command

$ sudo mkdir -p /data/db/

$ sudo chown id -u /data/db

and then the final command is..

$ mongod --journal

Do not close terminal until you are working with mongoDB

It works for me...

查看更多
登录 后发表回答