Option "useFindAndModify" is not supported
Asked Answered
H

3

3

I'm trying to connect to my database using mongoose and in my console is displaying ' option usefindandmodify is not supproted '. I'm using mongoose 6.0.0

this is my code

  mongoose.connect(constants.CONNECTION_URL,
     { useNewUrlParser: true,
       useUnifiedTopology: true, 
       useFindAndModify: false 
     })
.then(() => app.listen(constants.PORT, () => console.log(`Server Running on Port ${constants.PORT}`)))
.catch((error) => console.log(error.message));

mongoose.Promise = global.Promise;

can someone suggest me how can I get rid of that? is written with white if matters neither green nor red, white.

Hightail answered 25/8, 2021 at 1:23 Comment(0)
R
9

Starting with Mongoose version 6, you should not specify that as an option. It will be handled automatically.

This issue is explained here.

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.

Rickirickie answered 25/8, 2021 at 1:39 Comment(0)
H
0

i got this error too , so i fixed that like this
i guess useNewUrlParser, useUnifiedTopology, useFindAndModify are no longer available

mongoose.connect(constants.CONNECTION_URL).then(() => app.listen(constants.PORT, () => console.log(`Server Running on Port ${constants.PORT}`)))
.catch((error) => console.log(error.message));

mongoose.Promise = global.Promise;

mongoose.connect(CONNECTION_URL) .then(() => app.listen(PORT, () => console.log(Server running on port ${PORT})) ).catch((error) => console.log(error.message));
Helsa answered 9/1, 2022 at 14:38 Comment(2)
mongoose .connect(CONNECTION_URL) .then(() => app.listen(PORT, () => console.log(Server running on port ${PORT})) ) .catch((error) => console.log(error.message));Helsa
Welcome to Stack Overflow _ I've edited your answer and placed the code in your comment into the actual post _ In future please don't add additions in comments but click the 'Edit' button insteadLevorotation
A
0

New version of Mongoose don't support useFindAndModify, you don't have to write it in your code, Mongoose by default takes useFindAndModify as false.

just remove useFindAndModify from your code.

Applicator answered 21/2, 2022 at 14:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.