Home > other >  trying to connect mongoDB to my web app but it shows following error
trying to connect mongoDB to my web app but it shows following error

Time:09-16

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;

CodePudding user response:

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

  • Related