msbotframework-mongo-middlelayer icon indicating copy to clipboard operation
msbotframework-mongo-middlelayer copied to clipboard

deprecated db access method

Open zubcomandante opened this issue 9 years ago • 2 comments

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

zubcomandante avatar Jul 27 '17 13:07 zubcomandante

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); } });

};

zubcomandante avatar Sep 26 '17 09:09 zubcomandante

Thanks for solution

aakashkag avatar Oct 09 '17 09:10 aakashkag