open() is deprecated in mongoose >= 4.11.0, use openUri()
`open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead,
or set the `useMongoClient` option if using `connect()` or `createConnection()`.
See http://mongoosejs.com/docs/connections.html#use-mongo-client
Db.prototype.authenticate method will no longer be available in the next major
release 3.x as MongoDB 3.6 will only allow auth against users in the admin db
and will no longer allow multiple credentials on a socket.
Please authenticate using MongoClient.connect with auth credentials.
修改连接参数:
url = `mongodb://${this.username}:${this.password}@${this.host}:${this.port}/${this.dbName}`;
const opts = {
// autoReconnect: false,//默认true
// reconnectTries: 30,//尝试重连,默认30次
// reconnectInterval: 1000, //重连间隔,默认1000毫秒
loggerLevel: "warn", //error/warn/info/debug
useMongoClient: true
};
mongoose.connect(this.url, opts);
如果在原有参数的基础上加了userMongoClient
以后有如下警告:
[poolSize,ssl,sslValidate,sslCA,sslCert,sslKey,sslPass,sslCRL,autoReconnect,
noDelay,keepAlive,connectTimeoutMS,family,socketTimeoutMS,reconnectTries,
reconnectInterval,ha,haInterval,replicaSet,secondaryAcceptableLatencyMS,
acceptableLatencyMS,connectWithNoPrimary,authSource,w,wtimeout,j,
forceServerObjectId,serializeFunctions,ignoreUndefined,raw,bufferMaxEntries,
readPreference,pkFactory,promiseLibrary,readConcern,maxStalenessSeconds,
loggerLevel,logger,promoteValues,promoteBuffers,promoteLongs,domainsEnabled,
keepAliveInitialDelay,checkServerIdentity,validateOptions,appname,auth]
是因为不支持下面这种配置,将上面的poolSize,ssl,sslValidate...
这些参数直接提升到第一级,将下面配置:
mongoose.connect(this.url, {
db: {
native_parser: true
},
server: {
poolSize: 5,//默认为5
auto_reconnect: true
},
useMongoClient: true
})
改为这种方式:
mongoose.connect(this.url, {
poolSize:5,
autoReconnect: false,
useMongoClient: true
})