Question

How can I connect without to a distant database (MONGOHQ) without using MongoClient.connect() ?

var db, mongo, server;

mongo = require("mongodb");

server = new mongo.Server("mongodb://login:password@paulo.mongohq.com:10057//appname", 10057, {
 auto_reconnect: true
});

db = new mongo.Db("confirmed", server, { safe: true });

the message I get from my server is

[Error: failed to connect to [mongodb://login:password@paulo.mongohq.com:10057//appname:10057]]

Any ideas ?

Was it helpful?

Solution

You want something more like this, where you define the server as a DNS name (no protocol, port, auth or path):

server = new mongo.Server("paulo.mongohq.com", 10057, {
    auto_reconnect: true
});

db = new mongo.Db("confirmed", server, { safe: true });

and then once db is defined:

db.open(function(erreur, db) {
    db.authenticate('user', 'name', function(err, result) {
        //
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top