FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 1896 Ask New Question


I am using following Node code to connect to mongoDB

var mongodbUri = "mongodb://localhost:27017/db_name"
var settings = {
      server : {
        reconnectTries : Number.MAX_VALUE,
        autoReconnect : true
      }
    };
MongoClient.connect(mongodbUri, settings, function(err, dbref) {
  if (!err) {
    console.log("Mongodb connected");
    db = dbref;
  }else{
    console.log("Error while connecting to mongoDB" + err);
  }
});

With this code i am getting the following warning message on startup

the server/replset/mongos options are deprecated, all their options are supported at the top level of the options object
[poolSize,ssl,sslValidate,sslCA,sslCert,sslKey,sslPass,sslCRL,autoReconnect,noDelay,keepAlive,connectTimeoutMS,
socketTimeoutMS,reconnectTries,reconnectInterval,ha,haInterval,replicaSet,secondaryAcceptableLatencyMS,
acceptableLatencyMS,connectWithNoPrimary,authSource,w,wtimeout,j,forceServerObjectId,serializeFunctions
,ignoreUndefined,raw,promoteLongs,bufferMaxEntries,readPreference,pkFactory,promiseLibrary,readConcern,
maxStalenessSeconds,loggerLevel,logger,promoteValues,promoteBuffers,promoteLongs,domainsEnabled,
keepAliveInitialDelay,checkServerIdentity,validateOptions]
On By


1 Answer


As warning message saying server/replset/mongos options are deprecated, So you should not use them anymore instead you just need to move all of your server/replset/mongos options to root.
Update your code to following

var mongodbUri = "mongodb://localhost:27017/db_name"
var settings = {
      reconnectTries : Number.MAX_VALUE,
      autoReconnect : true
};
MongoClient.connect(mongodbUri, settings, function(err, dbref) {
  if (!err) {
    console.log("Mongodb connected");
    db = dbref;
  }else{
    console.log("Error while connecting to mongoDB" + err);
  }
});
On By


Answer This Question


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News