4

Error:

C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongodb\lib\connection_string.js:281 throw new error_1.MongoParseError(${optionWord} ${Array.from(unsupportedOptions).join(', ')} ${isOrAre} not supported); ^

MongoParseError: options usecreateindex, usefindandmodify are not supported at Object.parseOptions (C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongodb\lib\connection_string.js:281:15) at new MongoClient (C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongodb\lib\mongo_client.js:62:46) at C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongoose\lib\connection.js:781:16 at new Promise () at NativeConnection.Connection.openUri (C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongoose\lib\connection.js:778:19) at C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongoose\lib\index.js:330:10 at C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongoose\lib\helpers\promiseOrCallback.js:32:5 at new Promise () at promiseOrCallback (C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:10) at Mongoose._promiseOrCallback (C:\Users\Bpc\Desktop\devcamper_api\node_modules\mongoose\lib\index.js:1151:10)

and this is my code:

const mongoose = require('mongoose');

const connectDB = async () => {
    const conn = await mongoose.connect(process.env.MONGO_URI,
        {
            useNewUrlParser: true,
            useCreateIndex: true,
            useFindAndModify: false,
            useUnifiedTopology: true
        });
    console.log(`MongoDB Connected: ${conn.connection.host}`);
};

module.exports = connectDB;
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
mhmdrz mirdamadi
  • 73
  • 1
  • 1
  • 6
  • I’m voting to close this question because the response is clear in the log ` options usecreateindex, usefindandmodify are not supported` – callmemath Sep 15 '21 at 15:25

2 Answers2

12

Seems to be the same as: MongoParseError: options useCreateIndex, useFindAndModify are not supported

From the Mongoose 6.0 docs:

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.

Source: https://stackoverflow.com/a/68962378/7860331

Allard
  • 186
  • 1
  • 8
3

const uri = process.env.ATLAS_URI;
mongoose.connect(uri, {});

This worked for me