Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoParseError: options useCreateIndex, useFindAndModify are not supported

Tags:

mongodb

I tried to run it and it said an error like the title. and this is my code:

const URI = process.env.MONGODB_URL;  mongoose.connect(URI, {    useCreateIndex: true,     useFindAndModify: false,     useNewUrlParser: true,     useUnifiedTopology: true  }, err => {    if(err) throw err;    console.log('Connected to MongoDB!!!') }) 

I set the MONGODB_URL in .env :

MONGODB_URL = mongodb+srv://username:<password>@cluster0.accdl.mongodb.net/website?retryWrites=true&w=majority 

How to fix it?

like image 442
viiii Avatar asked Aug 27 '21 19:08

viiii


People also ask

Why is useCreateIndex not supported?

The error is because of the new version of the mongoose i.e version 6.0. 6. 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 .

What can I use instead of useCreateIndex?

What version of Mongoose are you using? The useCreateIndex option has been deprecated for a while and removed as of the Mongoose 6 release per No More Deprecation Warning Options: useNewUrlParser , useUnifiedTopology , useFindAndModify , and useCreateIndex are no longer supported options.

How do you use useUnifiedTopology true?

How to use it. The unified topology is available now behind the useUnifiedTopology feature flag. You can opt in to using it by passing the option to your MongoClient constructor: const client = MongoClient('mongodb://localhost:27017', { useUnifiedTopology: true });

What is useNewUrlParser?

useNewUrlParser : The underlying MongoDB driver has deprecated their current connection string parser. Because this is a major change, they added the useNewUrlParser flag to allow users to fall back to the old parser if they find a bug in the new parser.


1 Answers

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.

like image 64
Joe Avatar answered Sep 17 '22 02:09

Joe