MongoLab recently updated the mongoDb version to 3.x. To try to reproduce the environment, i updated my local version of node.js to 4.x, mongodb to 3.x and mongoose to 3.8.
In my local environment i'm able to connect to mongoDb but in heroku i can't. The following error occurs :
fail to connect to mongodb for address mongodb://user:password@host:port/dbname
I suspect an older version of mongoose, or a bad connection way, but why it works on my local environment? Here how i connect node to mongoDb :
var uriString = process.env.MONGOLAB_URI || process.env.MONGOHQ_URL
mongoose.connect(uriString, function (err, res) {
if (err) {
console.log('fail to connect to mongodb for address ' + uriString);
} else {
console.log('Connection to mongodb ok');
}
});
I found the answer,
It looks like MongoDB 3.0 is supported in Mongoose 4.0.0: Like mongodb doc illustrate
So after upgraded mongoose to v4.x i'm now able to connect to mongoDB using SCRAM SHA 1 credentials.
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.