mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

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

Open peterpeterparker opened this issue 9 years ago • 19 comments

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

peterpeterparker avatar Jul 05 '17 13:07 peterpeterparker

+1

cookie-ag avatar Jul 05 '17 18:07 cookie-ag

+1

HadrienR avatar Jul 06 '17 06:07 HadrienR

+1

flinn avatar Jul 06 '17 21:07 flinn

+1

edgarmarkosov avatar Jul 10 '17 15:07 edgarmarkosov

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

beeequeue avatar Jul 10 '17 18:07 beeequeue

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.

linsolas avatar Jul 11 '17 06:07 linsolas

Will add more details to the docs about thjs

vkarpov15 avatar Jul 13 '17 20:07 vkarpov15

@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 avatar Jul 28 '17 08:07 sulhome

@sulhome Just move it too main options object like this

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

tommarien avatar Jul 28 '17 08:07 tommarien

@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 avatar Jul 28 '17 10:07 sulhome

@sulhome both, as well as mongos.

vkarpov15 avatar Jul 30 '17 19:07 vkarpov15

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

tranzwalle avatar Aug 25 '17 03:08 tranzwalle

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

Happening here too.

CuAnnan avatar Oct 09 '17 00:10 CuAnnan

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

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

vkarpov15 avatar Oct 10 '17 23:10 vkarpov15

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

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

变成

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

highsea avatar Nov 28 '17 09:11 highsea

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 avatar Jan 10 '18 08:01 azachar

@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.

vkarpov15 avatar Jan 10 '18 21:01 vkarpov15

Thank you very much for your response!

Sent from my iPhone

On 10 Jan 2018, at 22:30, Valeri Karpov [email protected] 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.

azachar avatar Jan 10 '18 22:01 azachar

+1

karnavpargi avatar Jan 30 '18 07:01 karnavpargi