I am getting a deprecation warning message on my shell while using Node.js. It started showing up in the middle of my project, and I'm not sure how to get rid of it...
I have installed Axios, Express and Mongoose as dependencies. This is what my package.json looks like:
{
"name": "backend",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "nodemon src/index.js"
},
"dependencies": {
"axios": "^0.19.1",
"express": "^4.17.1",
"mongoose": "^5.8.7"
},
"devDependencies": {
"nodemon": "^2.0.2"
}
}
This is what shows on the terminal:
yarn run v1.17.0
$ nodemon src/index.js
[nodemon] 2.0.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node src/index.js`
(node:15702) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
Does anyone know how to get rid of the depecration warning?
(node:15702) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
Thanks!
I found a fix. Added => useCreateIndex: true, (worked like a charm).
mongoose.connect('mongodb+srv://<user>:<password>@cluster0-h2xcd.mongodb.net/<project>?retryWrites=true&w=majority', {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.