更新mongodb依赖项后发出警告

kal*_*yad 4 mongoose mongodb

我已经安装了最新版本的winston-mongodb。我注意到mongodbfrom winston-mongodb软件包的版本已从一个版本更新到1.6.6另一个2.0.7版本。更新后,我得到了warning

不建议使用server / replset / mongos选项,它们的所有选项均在选项对象的最高级别[poolSize,ssl,sslValidate,sslCA,sslCert,sslKey,sslPass,autoReconnect,noDelay,keepAlive,connectTimeoutMS,socketTimeoutMS,reconnectTries, reconnectInterval,ha,haInterval,副本集,secondaryAcceptableLatencyMS,acceptableLatencyMS,connectWithNoPrimary,authSource,w,wtimeout,j,forceServerObjectId,serializeFunctions,ignoreUndefined,raw,promoteLongs,bufferMaxEntries,readPreference,pkFactory,promiseLiconaryS,logger,ProfisenCons, PromotionBuffers,promoteLongs,domainsEnabled,keepAliveInitialDelay,checkServerIdentity,validateOptions]

我该如何解决?任何的想法?

Raj*_*jan 5

根据错误信息;

the server/replset/mongos options are deprecated, all their options are supported at the top level of the options object

因此,解决该问题的方法就是将设置选项从服务器,replset,socketOptions,mongos和任何其他层次结构选项移到对象的顶层。

mongoose.connect( 'mongodb://localhost/db',
  {
    useMongoClient: true,
    server: {
            ssl: true,
            socketOptions: {
                keepAlive: 300000,
                connectTimeoutMS: 30000
            },
            auto_reconnect: true,
            reconnectTries: 300000,
            reconnectInterval: 5000
        },
    promiseLibrary: global.Promise
  }
);

change it to;

mongoose.connect( 'mongodb://localhost/db',
  {
    useMongoClient: true,
    poolSize: 2,
    ssl: true,
    keepAlive: 300000,
    connectTimeoutMS: 30000,
    autoReconnect: true,
    reconnectTries: 300000,
    reconnectInterval: 5000,
    promiseLibrary: global.Promise
  }
);
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你!谢谢,