Home > OS >  I am trying to connect mongodb ATLAS
I am trying to connect mongodb ATLAS

Time:09-06

[nodemon] restarting due to changes... [nodemon] starting node server.js Server is running on port: ${port} D:\Practice\mern\mern-exercise\backend\node_modules\mongodb\lib\connection_string.js:290 throw new error_1.MongoParseError(${optionWord} ${Array.from(unsupportedOptions).join(', ')} ${isOrAre} not supported); ^

MongoParseError: option usecreateindex is not supported at parseOptions (D:\Practice\mern\mern-exercise\backend\node_modules\mongodb\lib\connection_string.js:290:15) at new MongoClient (D:\Practice\mern\mern-exercise\backend\node_modules\mongodb\lib\mongo_client.js:64:63) at D:\Practice\mern\mern-exercise\backend\node_modules\mongoose\lib\connection.js:801:16 at new Promise () at Connection.openUri (D:\Practice\mern\mern-exercise\backend\node_modules\mongoose\lib\connection.js:798:19) at D:\Practice\mern\mern-exercise\backend\node_modules\mongoose\lib\index.js:380:10 at D:\Practice\mern\mern-exercise\backend\node_modules\mongoose\lib\helpers\promiseOrCallback.js:41:5 at new Promise () at promiseOrCallback (D:\Practice\mern\mern-exercise\backend\node_modules\mongoose\lib\helpers\promiseOrCallback.js:40:10) at Mongoose._promiseOrCallback (D:\Practice\mern\mern-exercise\backend\node_modules\mongoose\lib\index.js:1225:10) { [Symbol(errorLabels)]: Set(0) {} }

Node.js v18.7.0 [nodemon] app crashed - waiting for file changes before starting...

And the code is

const cors = require('cors');
const mongoose = require('mongoose');

require('dotenv').config();

const app = express ();
const port = process.env.PORT || 5000;

app.use(cors());
app.use(express.json());

const uri = process.env.ATLAS_URI;
mongoose.connect(uri, {useNewUrlParser: true, useCreateIndex: true}
  );
const connection = mongoose.connection;
connection.once('open', ()=>{
  console.log("MongoDB database connection established successfully");
})

app.listen(port, () => {
  console.log('Server is running on port: ${port}')
}); 

process.on('warning', e => console.warn(e.stack));```

CodePudding user response:

According to the mongoose docs

useCreateIndex isn't an option to mongooose.connect()

  • Related