首页 文章

更新mongodb依赖项后发出警告

提问于
浏览
3

我安装了最新版本的 winston-mongodb . 我注意到 winston-mongodb 包的 mongodb 版本已从 1.6.6 版本更新为 2.0.7 版本 . 更新后我得到了这个 warning

不推荐使用server / replset / mongos选项,在options对象的顶层支持所有选项[poolSize,ssl,sslValidate,sslCA,sslCert,sslKey,sslPass,autoReconnect,noDelay,keepAlive,connectTimeoutMS,socketTimeoutMS,reconnectTries ,reconnectInterval,哈,haInterval,replicaSet,secondaryAcceptableLatencyMS,acceptableLatencyMS,connectWithNoPrimary,authSource,W,wtimeout,J,forceServerObjectId,serializeFunctions,ignoreUndefined,生,promoteLongs,bufferMaxEntries,readPreference,pkFactory,promiseLibrary,readConcern,maxStalenessSeconds,loggerLevel, Logger ,promoteValues ,promoteBuffers,promoteLongs,domainsEnabled,keepAliveInitialDelay,checkServerIdentity,validateOptions]

我怎么解决这个问题?任何的想法?

3 回答

  • 0

    根据错误信息;

    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,
        useMongoClient: true,
        promiseLibrary: global.Promise
      }
    );
    

    希望能帮助到你!谢谢,

  • 3

    I noticed this as well.
    看来这是一个非致命的错误,因为这个问题已经关闭 . 见:https://jira.mongodb.org/browse/NODE-941 . 我测试过:mongodb@2.2.24 - 当你报告警告时给出!!! mongodb@2.2.23 - 因错误而死亡 . mongodb@2.2.22 - 没有警告,工作正常....

    So I would recommend to install verson 2.2.22 现在看看给出了 . 这就是我所做的 - 因为我不喜欢看到警告 .
    我希望这有帮助 .

  • 0

    如果从4.x升级到5.x并且您没有在4.x中使用useMongoClient选项,则可能会看到以下弃用警告:

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

    在旧版本的MongoDB驱动程序中,您必须为服务器连接,副本集连接和mongos连接指定不同的选项:

    mongoose.connect(myUri, {
      server: {
        socketOptions: {
          socketTimeoutMS: 0,
          keepAlive: true
        },
        reconnectTries: 30
      },
      replset: {
        socketOptions: {
          socketTimeoutMS: 0,
          keepAlive: true
        },
        reconnectTries: 30
      },
      mongos: {
        socketOptions: {
          socketTimeoutMS: 0,
          keepAlive: true
        },
        reconnectTries: 30
      }
    });
    

    在mongoose v5.x中,您可以在顶层声明这些选项,而不需要额外的嵌套 .

    // Equivalent to the above code
    mongoose.connect(myUri, {
      socketTimeoutMS: 0,
      keepAlive: true,
      reconnectTries: 30
    });
    

    来源:官方文件http://mongoosejs.com/docs/connections.html

相关问题