gpt4 book ai didi

node.js - 使用winston-mongodb后收到警告[当前服务器发现和监控引擎已被弃用]

转载 作者:行者123 更新时间:2023-12-02 18:11:29 25 4
gpt4 key购买 nike

安装winston-mongodb后,我收到以下警告:

(node:9316) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

这是我的 app.js :

require('express-async-errors');

const express = require('express'),
config = require('config'),
morgan = require('morgan'),
helmet = require('helmet'),
winston = require('winston'),
mongoose = require('mongoose');

require('winston-mongodb');


mongoose.connect("mongodb://localhost:27017/wsep",
{ useNewUrlParser: true, useFindAndModify: false, useCreateIndex: true, useUnifiedTopology: true })
.then(connect => { console.log("connected to mongo db...") })
.catch(error => { console.log("could not connect to mongo db ...") })

winston.add(new winston.transports.MongoDB({
db: 'mongodb://localhost:27017/wsep'
}));

如果我删除/注释以下代码片段,上面的警告将消失:

winston.add(new winston.transports.MongoDB({
db: 'mongodb://localhost:27017/wsep'
}));

编辑:

package.json

{
"name": "backend-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon app.js",
"start": "node app.js"
},
"engines": {
"node": "13.5.0"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"compression": "^1.7.4",
"config": "^3.2.5",
"express": "^4.17.1",
"express-async-errors": "^3.1.1",
"helmet": "^3.21.2",
"joi": "^14.3.1",
"jsonwebtoken": "^8.5.1",
"jwt-token-encrypt": "^1.0.4",
"lodash": "^4.17.15",
"mongoose": "^5.8.9",
"multer": "^1.4.2",
"winston": "^3.2.1",
"winston-mongodb": "^5.0.1"
},
"devDependencies": {
"nodemon": "^2.0.2"
}
}

最佳答案

您只需将 useUnifiedTopology: true 添加到 winston-mongodb 的选项 block 即可像这样:

winston.add(new winston.transports.MongoDB({
db: 'mongodb://localhost:27017/wsep',
options: {
useUnifiedTopology: true,
}
}));

关于node.js - 使用winston-mongodb后收到警告[当前服务器发现和监控引擎已被弃用],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59931450/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com