4
votes

I've installed the latest version of winston-mongodb. I've noticed that the version of mongodb from winston-mongodb package has updated from 1.6.6 version to 2.0.7 version. After updating I got this warning:

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,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]

How can I solve this? Any idea?

3

3 Answers

5
votes

According to the error message;

the server/replset/mongos options are deprecated, all their options are supported at the top level of the options object

so, solution for the problem is simply moving the setting options from the server, replset, socketOptions, mongos and any other hierarchy options up into the top level of the object.

mongoose.connect( 'mongodb://localhost/db',
  {
    useMongoClient: true,
    server: {
            ssl: true,
            socketOptions: {
                keepAlive: 300000,
                connectTimeoutMS: 30000
            },
            auto_reconnect: true,
            reconnectTries: 300000,
            reconnectInterval: 5000
        },
    promiseLibrary: global.Promise
  }
);

change it to;

mongoose.connect( 'mongodb://localhost/db',
  {
    useMongoClient: true,
    poolSize: 2,
    ssl: true,
    keepAlive: 300000,
    connectTimeoutMS: 30000,
    autoReconnect: true,
    reconnectTries: 300000,
    reconnectInterval: 5000,
    promiseLibrary: global.Promise
  }
);

Hope it helps! Thanks,

0
votes

I noticed this as well.
It seems that is is a non-fatal bug, as this issue was closed. See: https://jira.mongodb.org/browse/NODE-941 . I tested with: mongodb@2.2.24 - gives as you reported warnings!!! mongodb@2.2.23 - dies with an error. mongodb@2.2.22 - no warnings and works fine....

So I would recommend to install verson 2.2.22 for now and see that gives. That is what I did - since I don't like to see warnings.
I hope this helps.

0
votes

You may see the following deprecation warning if upgrading from 4.x to 5.x and you didn't use the useMongoClient option in 4.x:

the server/replset/mongos options are deprecated, all their options are supported at the top level of the options object

in older version of the MongoDB driver you had to specify distinct options for server connections, replica set connections, and mongos connections:

    mongoose.connect(myUri, {
  server: {
    socketOptions: {
      socketTimeoutMS: 0,
      keepAlive: true
    },
    reconnectTries: 30
  },
  replset: {
    socketOptions: {
      socketTimeoutMS: 0,
      keepAlive: true
    },
    reconnectTries: 30
  },
  mongos: {
    socketOptions: {
      socketTimeoutMS: 0,
      keepAlive: true
    },
    reconnectTries: 30
  }
});

In mongoose v5.x you can instead declare these options at the top level, without all that extra nesting.

// Equivalent to the above code
mongoose.connect(myUri, {
  socketTimeoutMS: 0,
  keepAlive: true,
  reconnectTries: 30
});

Source: Official Documentation http://mongoosejs.com/docs/connections.html