Can't get the Mongo portion of my heroku app to work
I've looked through several stackoverflow articles and tried different
ways of connection but none of them work. So far I've tried:
var mongodb = require('mongodb');
var uri = 'mongodb://Userxxx:Passxxx@ds0URI:PORT/heroku_appXXX';
mongodb.MongoClient.connect(uri, { server: { auto_reconnect: true } },
function (err, db) {
});
That crashed with the following error:
TypeError: Cannot call method 'connect' of undefined
Then I tried this:
mongo = require('mongodb')
Server = mongo.Server
Db = mongo.Db
BSON = mongo.BSONPure;
con = null;
server = new Server('xxxxx.mongolab.com', 'PORT', {auto_reconnect: true});
DBCon = new Db('xxxxx', server, {safe: false});
DBCon.open(function(err, db) {
if(!err) {
db.authenticate('xxxxx', 'xxxxx', function(err){
if(!err) con = db;
})
}
});
And that gave me an error:
/app/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:10
number') throw "host and port must be specified [" + host + ":" + port +
"]"; host and port must be specified
Does anyone know the right way to do this?
No comments:
Post a Comment