简体   繁体   中英

why am getting error with MongoClient()?

Actually am new to this mongodb.

Here mongo was visible on localhost and phpinfo(). for

http://127.0.0.1:27017/

also getting like "It looks like you are trying to access MongoDB over HTTP on the native driver port." . From command prompt also am able to run mongo.

But still am getting an error while using Mongo()/MongoClient from program.

Deprecated: main(): The Mongo class is deprecated, please use the MongoClient class in C:\wamp\www\mongo\new.php on line 2

Fatal error: Uncaught exception 'MongoConnectionException' with message ' in C:\wamp\www\mongo\new.php on line 4
( ! ) MongoConnectionException: Failed to connect to: example.com:27017: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\wamp\www\mongo\new.php on line 4

How i can solve these issues?

This error is usually caused when using the deprecated Mongo class, which has long been replaced with the MongoClient class, the new MongoClient class requires you to create a connection like this $m = new MongoClient(); previously using the old class it would have looked like this $m = new Mongo();

If you would like to read more on this http://php.net/manual/en/class.mongoclient.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM