当我开始构建我的后端服务器时,我收到了这个弃用警告,但它显示我已连接到数据库。
文件 server.js
const dotenv = require('dotenv');
const mongoose = require('mongoose');
const app = express();
dotenv.config();
mongoose
.connect(process.env.MONGODB_URI)
.then(() => {
console.log('connected to db');
})
.catch((err) => {
console.log(err.message);
});
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`serve at http://localhost:${port}`);
});
文件 package.json
{
"name": "backend",
"version": "1.0.0",
"description": "backend",
"main": "server.js",
"scripts": {
"start": "node server",
"dev": "nodemon server"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^16.0.3",
"express": "^4.18.2",
"mongoose": "^6.8.0"
},
"devDependencies": {
"nodemon": "^2.0.20"
}
}
这是Mongoose的弃用警告:
它显示:
[MONGOOSE] DeprecationWarning: Mongoose: the `strictQuery` option will be switched back to `false` by default in Mongoose 7.
Use `mongoose.set('strictQuery', false);` if you want to prepare for this change.
Or use `mongoose.set('strictQuery', true);` to suppress this warning.
(Use `node --trace-deprecation ...` to show where the warning was created)
strictQuery
option will be switched back tofalse
by default in Mongoose 7. Usemongoose.set('strictQuery', false);
if you want to prepare for this change. Or usemongoose.set('strictQuery', true);
to suppress this warning. - DummyData1590