Solvedmongoose server/replset/mongos options are deprecated => documentation?

Do you want to request a feature or report a bug?

Documentation enhancement

What is the current behavior?

Using Mongoose 4.11.1 I get following deprecation 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,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]

What is the expected behavior?

Following the warning, I was searching the documentation about how to resolve this warning (http://mongoosejs.com/docs/connections.html#use-mongo-client) but didn't found anything about it aka anything about how I should migrate these options

Please mention your node.js, mongoose and MongoDB version.

Node.js v8.1.3
Mongoose 4.11.1
Mongodb v3.2.14

20 Answers

✔️Accepted Answer

The message says that all of the server, replset, and mongos options have been moved to the top level of the options object.

Simply move the settings from the server, replset, and mongos keys up into the top level of the object.

mongoose.connect( 'mongodb://localhost/db',
  {
    useMongoClient: true,
    server: {
      poolSize: 2
    },
    promiseLibrary: global.Promise
  }
);

turns into

mongoose.connect( 'mongodb://localhost/db',
  {
    useMongoClient: true,
    poolSize: 2,
    promiseLibrary: global.Promise
  }
);

Other Answers:

Will add more details to the docs about thjs

just put all the options in top level, it works.

old format:
var options = {
db: { native_parser: true },
server: { poolSize: 5 }
}
mongoose.connect(uri, options);

new format (just one level):
var options = {
native_parser: true,
poolSize: 5,
}
mongoose.connect(uri, options);