. Advertisement .
..3..
. Advertisement .
..4..
The error: “MongoParseError: options useCreateIndex useFindAndModify are not supported” is a common error that can show up in many ways. In this blog, we will go through some of the ways you can fix this issue. Read on.
What is “MongoParseError: options useCreateIndex useFindAndModify are not supported”?
When attempting to connect to your MongoDB database, you may get the following error.
MongoParseError: options useCreateIndex useFindAndModify are not supported
Here can be your connection code.
mongoose.connect(MONGODB_URL, {
useCreatendex: true,
useFindAndModify: false,
useNewUrlParser: true,
useUnifiedTopology: true
}, err => {
console.log(err)
})
What causes error?
The current latest version 6.0.6 of mongoose has some functionality that is not supported anymore. In the above error situation, the main cause is usecreateindex, usefindandmodify is not supported anymore. The way to deal with you is to delete these options.
How to fix the error?
Here are some methods with detailed step-by-step instructions. Take a look and choose the method that works for you.
Approach 1: Delete options
The useNewUrlParser, useFindAndModify, useUnifiedTopology, and useCreateIndex options are no longer supported in Mongoose 6.0. As a result, that option is no longer available. so try connecting in the same way as before.
const URI = process.env.MONGODB_URL;
mongoose.connect(URI, {
useNewUrlParser: true,
useUnifiedTopology: true
}, err => {
if(err) throw err;
console.log('Connected to MongoDB!!!')
})
or:
Mongoose.connect(
MONGODB_URL,
async(err)=>{
if(err) throw err;
console.log("conncted to db")
}
Approach 2:
Use the code below, It has the function of checking and updating your connections.
mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology:
true });
const connection = mongoose.connection;
try{
connection.once('open', () => {
console.log("MongoDB database connection established
successfully");
})
} catch(e) {
console.log(e);
}
function close_connection() {
connection.close();
}
Approach 3: Downgrade to under 6.0
If you still want to utilize Options, downgrade your Mongoose version under 6.0, as useUnifiedTopology, useNewUrlParser, useFindAndModify, and useCreateIndex are no longer backed options in Mongoose 6.0.
Conclusion
We hope you enjoyed our article about the error. With this knowledge, we know that you can fix your error: “MongoParseError: options useCreateIndex useFindAndModify are not supported” quickly by following these steps! If you still have any other questions about fixing this syntax error, please leave a comment below. Thank you for reading!
Leave a comment