Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
peterpeterparker opened this issue Jul 5, 2017 · 19 comments
Closed
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Milestone

Comments

@peterpeterparker
Copy link

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

@cookie-ag
Copy link

+1

2 similar comments
@HadrienR
Copy link

HadrienR commented Jul 6, 2017

+1

@flinn
Copy link

flinn commented Jul 6, 2017

+1

@edgarmarkosov
Copy link

+1

@BeeeQueue
Copy link

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

@linsolas
Copy link

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. winstonjs/winston-mongodb#90), and the warnings are now gone.

@vkarpov15 vkarpov15 added this to the 4.11.4 milestone Jul 13, 2017
@vkarpov15 vkarpov15 added the docs This issue is due to a mistake or omission in the mongoosejs.com documentation label Jul 13, 2017
@vkarpov15
Copy link
Collaborator

Will add more details to the docs about thjs

@sulhome
Copy link

sulhome commented Jul 28, 2017

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

@tommarien
Copy link
Contributor

@sulhome Just move it too main options object like this

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

@sulhome
Copy link

sulhome commented Jul 28, 2017

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

@vkarpov15
Copy link
Collaborator

@sulhome both, as well as mongos.

@tranzwalle
Copy link

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

dancgray added a commit to deltanet/adapt_authoring that referenced this issue Sep 22, 2017
@CuAnnan
Copy link

CuAnnan commented Oct 9, 2017

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

Happening here too.

@vkarpov15
Copy link
Collaborator

vkarpov15 commented Oct 10, 2017

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

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

@highsea
Copy link

highsea commented Nov 28, 2017

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

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

变成

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

@azachar
Copy link

azachar commented Jan 10, 2018

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

@vkarpov15
Copy link
Collaborator

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

@azachar
Copy link

azachar commented Jan 10, 2018 via email

@karnavpargi
Copy link

+1

@Automattic Automattic locked as resolved and limited conversation to collaborators Jan 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Projects
None yet
Development

No branches or pull requests