Mongoose: server/replset/mongos options are deprecated => documentation?

Created on 5 Jul 2017  ·  19Comments  ·  Source: Automattic/mongoose

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

docs

Most helpful comment

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

All 19 comments

+1

+1

+1

+1

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

Hello,

Just for information, on my case I used an old version of winston-mongodb (v1), and got these warnings.
I upgraded to v2 (cf. https://github.com/winstonjs/winston-mongodb/issues/90), and the warnings are now gone.

Will add more details to the docs about thjs

@BeeeQueue I am still getting this warning message. Here is what I am doing

options and connect

const options = {
    useMongoClient: true,
    server: { socketOptions: { keepAlive: 300000, connectTimeoutMS: 30000 } },
    replset: { socketOptions: { keepAlive: 300000, connectTimeoutMS: 30000 } }
};

mongoose.connect(<url>, options)
    .then(() => {
        logger.log('info', 'connected to mongodb');
    })
    .catch((error) => {
        logger.log('info', 'error connecting to db: ' + error);
    });

warning message

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

@sulhome Just move it too main options object like this

const options = {
    useMongoClient: true,
    keepAlive: 300000, 
    connectTimeoutMS: 30000,
};

@tommarien but there is keepAlive and connectTimeoutMS for server and for replset as well so when you put it on the top level which one are you setting the value for? server or replset?

@sulhome both, as well as mongos.

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

mongoose.connect(
mongoString,
{
useMongoClient:true,
db:mongoConf.db
}
);

Happening here too.

@CuAnnan the below should work. Promote your db options to the top level options object.

mongoose.connect(
mongoString,
Object.assign({
useMongoClient:true
}, mongoConf.db)
);

原来是将 options 对象配置 提升到了顶级
那么文档 中的 keepAlive 设置也要改了吧~

options.server.socketOptions = options.replset.socketOptions = { keepAlive: 120 };

变成

options = { socketTimeoutMS: 0, keepAlive: true, reconnectTries: 30 }

Hi there,
Could any one suggest, what to use instead of

options: {
    db : {
        safe: true
    }
}

This code can be located from https://github.com/angular-fullstack/generator-angular-fullstack/blob/ab8624002cd90aac100dbb6cc263d92f7f599588/templates/app/server/config/environment/index.js#L43 which still uses mongoose before 4.12, I want to upgrade it but cannot find any relevant migration info for this.

Thanks for any pieces of advice!

Cheers,
Andrej

@azachar here's some docs: http://mongoosejs.com/docs/connections.html#use-mongo-client . However, using safe is no longer necessary because the mongodb driver uses acknowledged writes by default now, safe was a 2011-2012 construct to turn on acknowledged writes and journaling in one command, but it is now an anachronism. I would recommend just removing it entirely.

Thank you very much for your response!

Sent from my iPhone

On 10 Jan 2018, at 22:30, Valeri Karpov notifications@github.com wrote:

@azachar here's some docs: http://mongoosejs.com/docs/connections.html#use-mongo-client . However, using safe is no longer necessary because the mongodb driver uses acknowledged writes by default now, safe was a 2011-2012 construct to turn on acknowledged writes and journaling in one command, but it is now an anachronism. I would recommend just removing it entirely.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

+1

Was this page helpful?
0 / 5 - 0 ratings