node.js - 显示弃用警告 `the server/replset/mongos/db options are deprecated`

标签 node.js mongodb mongoose

如何在使用带有选项 server.ssl 的 mongoose 5.2.17 连接到 mongo 后删除此警告。

the server/replset/mongos/db 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,keepAliveInitialDelay,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,checkServerIdentity,validateOptions,appname,auth,user,password,authMechanism,compression,fsync,readPreferenceTags,numberOfRetries,auto_reconnect,minSize,monitorCommands,retryWrites,useNewUrlParser]

最佳答案

从警告消息中我发现的内容有据可查here.

它说,serverreplsetmongos 键的设置移动到对象的顶层.

// The options inside the `server` attributes are moved to its parents.
// Same happens to `replset` and `mongos`
// Change this
mongoose.connect( 'mongodb://localhost/db',
  {
    useMongoClient: true,
    server: {
      poolSize: 2
    },
    promiseLibrary: global.Promise
  }
);

// To this
mongoose.connect( 'mongodb://localhost/db',
  {
    useMongoClient: true,
    poolSize: 2,
    promiseLibrary: global.Promise
  }
);

有关更多信息,请参阅 options in mongoose docs.

关于node.js - 显示弃用警告 `the server/replset/mongos/db options are deprecated`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52696224/

相关文章:

javascript - 从nodejs在客户端发送JWT token 是否存在安全风险

angularjs - 使用 MEAN + Passport 根据用户角色更改 View

node.js - ERR_HTTP_HEADERS_SENT : Cannot set headers after they are sent to the client

node.js - 如何在 Mongoose 的虚拟方法中填充引用字段?

javascript - Node.js:在模块范围内使用时, `this` 运算符的上下文是什么?

javascript - 使用nodejs分割字符串并转换为json对象

javascript - 在一个请求中将多个对象放入 S3

node.js - 持久队列: serialize/deserialize queue object in node-amqp

mongodb - 如何将 NoSQL 与 Data Vault 2.0 建模集成?如何使用哈希键来集成NoSQL DB?

mongodb - 如何删除MongoDB中的多个关系文档?