how to fix Mongoose Deprecation Warning "the strictQuery"
when i start build my backend server i get this deprecation warning, but its show that im connected to database. i just search the solution in youtube and re-create again but its still didnt work. this is my code ...
in server.js
const dotenv = require('dotenv');
const mongoose = require('mongoose');
const app = express();
dotenv.config();
mongoose
.connect(process.env.MONGODB_URI)
.then(() => {
conso开发者_开发问答le.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}`);
});
in 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"
}
}
and this is the Mongoose Deprecation Warning enter image description here
its show :
(node:8392) [MONGOOSE] DeprecationWarning: Mongoose: the `strictQuery` o` if you want to prepare for this change. Or use `mongoose.set('strictQu
(Use `node --trace-deprecation ...` to show where the warning was create
serve at http://localhost:5500
connected to db
i dont know where to fix this error because i think its come from my node_modules. how can i fix this warning? is this warning gonna impact when im gonna connect my frontend to backend or its gonna impact when im gonna deploy? sorry im just beginner.
i start build my backend server i get this deprecation warning, but its show that im connected to database. i just want fix the warning. i re-create this backend again but its still didnt work, its still show the deprecation warning
This warning was introduced to notify users about the change that will be introduced in Mongoose 7 to the default value of strictQuery
.
It's default value will be brought back to false
.
You can either set the strictQuery
option to true
globally to suppress the warning with:
const dotenv = require('dotenv');
const mongoose = require('mongoose');
const app = express();
dotenv.config();
mongoose.set('strictQuery', true);
Or, set the flag to false
if you want to override the current strictQuery
behavior and prepare for the new release:
const dotenv = require('dotenv');
const mongoose = require('mongoose');
const app = express();
dotenv.config();
mongoose.set('strictQuery', false);
Either way the warning should disappear.
For more information on why strictQuery
will be brought back to false
by default see here.
For more information on strictQuery
see here.
精彩评论