Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid option in mongoose

Just started following a tutorial, however when I try to start my very basic node app i get

 if (VALID_OPTIONS.indexOf(key) === -1) throw new Error(`\`${key}\` is an invalid option.`);
                                               ^

Error: `false` is an invalid option.

I only have minimal code so far and haven't found anything for this and don't understand what could go wrong with so little code, commenting out the 'usefindandmodify' that has false doesnt fix it

import express from "express";
import bodyParser from "body-parser";
import mongoose from "mongoose";
import cors from "cors";

const app = express();

app.use(bodyParser.json({ limit: "30mb", extender: true }));
app.use(bodyParser.urlencoded({ limit: "30mb", extender: true }));
app.use(cors());

const CONNECTION_URL =
  "mongodb+srv://<passandstuff>@cluster0.gber6.mongodb.net/myFirstDatabase?retryWrites=true&w=majority";
const PORT = process.env.PORT || 5000;

mongoose
  .connect(CONNECTION_URL, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  })
  .then(() =>
    app.listen(PORT, () => console.log(`server running on port: ${PORT}`))
  )
  .catch((error) => console.log(error.message));

mongoose.set(("useFindAndModify", false));
like image 985
Whisky-Toad Avatar asked Oct 28 '25 15:10

Whisky-Toad


1 Answers

If you are using mongoose 6 these options unnecessary

Mongoose 6 always behaves as if useNewUrlParser, useUnifiedTopology, and useCreateIndex are true, and useFindAndModify is false. Please remove these options from your code.

https://mongoosejs.com/docs/migrating_to_6.html#no-more-deprecation-warning-options

like image 108
Artem Yarmoliuk Avatar answered Oct 31 '25 06:10

Artem Yarmoliuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!