0

I am new to web and trying to MongoDB database using Mongoose. Why am I getting an error?

const express = require("express");
const app= express();
const dotenv = require("dotenv");
const mongoose = require("mongoose");

dotenv.config();

mongoose.connect(process.env.MONGO_URL, {
    useNewUrlParser: true,
     useUnifiedTopology: true,
     useCreateIndex: true,
  })
 .then(console.log("Connected to MongoDB"))
 .catch((err) => console.log(err));

app.listen("5000",() => {
console.log("Backend  is running");
 });

I am getting the following error:

yarn start
yarn run v1.22.19
$ nodemon index.js
[nodemon] 2.0.19
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
Connected to MongoDB
Backend  is running
MongoParseError: option usecreateindex is not supported
    at parseOptions (C:\Users\malli\Shaban's program\hackhathon\techathon\api\node_modules\mongodb\lib\connection_string.js:290:15)
    at new MongoClient (C:\Users\malli\Shaban's program\hackhathon\techathon\api\node_modules\mongodb\lib\mongo_client.js:64:63)
    at C:\Users\malli\Shaban's program\hackhathon\techathon\api\node_modules\mongoose\lib\connection.js:801:16
    at new Promise (<anonymous>)
    at NativeConnection.Connection.openUri (C:\Users\malli\Shaban's program\hackhathon\techathon\api\node_modules\mongoose\lib\connection.js:798:19)
    at C:\Users\malli\Shaban's program\hackhathon\techathon\api\node_modules\mongoose\lib\index.js:380:10    
    at C:\Users\malli\Shaban's program\hackhathon\techathon\api\node_modules\mongoose\lib\helpers\promiseOrCallback.js:41:5
    at new Promise (<anonymous>)
    at promiseOrCallback (C:\Users\malli\Shaban's program\hackhathon\techathon\api\node_modules\mongoose\lib\helpers\promiseOrCallback.js:40:10)
    at Mongoose._promiseOrCallback (C:\Users\malli\Shaban's program\hackhathon\techathon\api\node_modules\mongoose\lib\index.js:1233:10) {
  [Symbol(errorLabels)]: Set(0) {}
}

How can I resolve this?

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

0

You need to delete

useCreateIndex: true,

same happened to me when i updated the mongoose version