Invalid option in mongoose

Viewed 5962

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));
3 Answers

Remove this line from the code it will work fine after that as it is no longer used currently

mongoose.set('useFindAndModify', false);

First of all, you can remove { useNewUrlParser: true, useUnifiedTopology: true } and mongoose.set(("useFindAndModify", false)); as others have said.

And lastly ensure that you've set your username and password correctly and is matching with the mongodb admin. And then it should work!

Related