MongoParseError: options useCreateIndex, useFindAndModify are not supported
Solution 1:
From the Mongoose 6.0 docs:
useNewUrlParser, useUnifiedTopology, useFindAndModify, and useCreateIndex are no longer supported options. Mongoose 6 always behaves as if useNewUrlParser, useUnifiedTopology, and useCreateIndex are true, and useFindAndModify is false. Please remove these options from your code.
Solution 2:
Same problem was with me but if you remove useCreateIndex, useFindAndModify it will solve the problem just write :
const URI = process.env.MONGODB_URL;
mongoose.connect(URI, {
useNewUrlParser: true,
useUnifiedTopology: true
}, err => {
if(err) throw err;
console.log('Connected to MongoDB!!!')
});
It worked for me.
Solution 3:
No More Deprecation Warning Options
useNewUrlParser
, useUnifiedTopology
, useFindAndModify
, and useCreateIndex
are no longer supported options. Mongoose 6 always behaves as if useNewUrlParser
, useUnifiedTopology
, and useCreateIndex
are true, and useFindAndModify
is false. Please remove these options from your code.
src --> https://mongoosejs.com/docs/migrating_to_6.html#no-more-deprecation-warning-options
// No longer necessary:
mongoose.set('useFindAndModify', false);
await mongoose.connect('mongodb://localhost:27017/test', {
useNewUrlParser: true, // <-- no longer necessary
useUnifiedTopology: true // <-- no longer necessary
});