[Solved] MongoParseError: options useCreateIndex, useFindAndModify are not supported
Article
Mashpy Rahman
Problem:
MongoParseError: options useCreateIndex, useFindAndModify are not supported
I got this error after running this code -
const URI = process.env.MONGODB_URL; mongoose.connect(URI, { useCreatendex: true, useFindAndModify: false, useNewUrlParser: true, useUnifiedTopology: true }, err => { if(err) throw err; console.log('Test connection') })
Solution:
On Mongoose 6.0 useNewUrlParser, useUnifiedTopology, useFindAndModify, and useCreateIndex are always true and .useFindAndModify is false. No need to use on your code. You can write code like this -
const mongoose = require('mongoose');
var url = "mongodb+srv://username:@cluster0.accdl.mongodb.net/website?
retryWrites=true&w=majority";
mongoose.connect(url, function(err, db) {
if (err) throw err;
console.log("Database created!");
db.close();
});
Thank you for reading the article. Hope this will solve the problem. If not, please write your comment below.