简体   繁体   中英

Establish a simple mongohq connection

Is there a way to establish a connection to a cloud mongoDB (such as mongoHQ), with no drivers or third party apps, from a localhost server?

In other words, I want to host my php files locally, and connect to a mongoDB on the cloud.

I've been doing simple websites using php and MySQL as a hobbie for a few years, and I'm pretty decent at it, but I haven't been able to figure out how to do this one simple thing with Mongo.

Whenever I run a file that does:

$m = new Mongo('mongodb://username:password@staff.mongohq.com:XXXXX/database');

from a php file, I get a HTTP 500 error.

Any help would be greatly appreciated. In advance I apologize if this isn't clear enough, this is my first post on SO. Please let me know if more info is needed.

Have you looked at your PHP/apache error log to see what the HTTP 500 error is ? Try adding to the top of your script:

ini_set('display_errors',1); 
error_reporting(E_ALL);

Based on your code sample, I would check that you have the Mongo module installed as it will generally not be included by default. Use phpinfo() and look for the mongo section.

If you want to use MongoHQ without installing a Mongo driver, you could also try their REST API which apparently is still in beta phase.

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