deprecated db access method
Hi,
I've noticed that the method you chose to establish the connection with mongoDb is deprecated:
"Db.prototype.authenticate method will no longer be available in the next major release 3.x as MongoDB 3.6 will only allow auth against users in the admin db and will no longer allow multiple credentials on a socket. Please authenticate using MongoClient.connect with auth credentials."
Are you planning to move to MongoClient?
Thank you very much, looking forward to you reply
Marco
Solved, this is what I did in my code:
var Db = require('mongodb').Db; var MongoClient = require('mongodb').MongoClient var connectionInstance; var conf = require('../config/mongoconf.js');
module.exports = function (callback) {
//if already we have a connection, don't connect to database again if (connectionInstance) { callback(null, connectionInstance); return; }
var mongoUrl = conf.mongoIp + ":" + conf.mongoPort + "/" + conf.DatabaseName; if ((conf.username.length > 0) && (conf.password.length > 0)) { mongoUrl = conf.username + ":" + conf.password + "@" + mongoUrl; } mongoUrl = "mongodb://" + mongoUrl;
MongoClient.connect(mongoUrl, { autoReconnect: true, connectTimeoutMS: 1000, reconnectInterval: 2000, reconnectTries: Number.MAX_VALUE }, function (err, db) { if (err) { console.log("Error connecting to the DB: ", err); } else { connectionInstance = db; callback(null, db); } });
};
Thanks for solution