1

This is frustrating. No clues why I got this error while documentation still has it. Please help!

My code to connect MongoDB with mongoose.

const mongoose = require('mongoose');

const connectDB = async () => {
    try {
        const conn = await mongoose.connect(process.env.MONGO_URI, {
            useNewUrlParser: true,
            useCreateIndex: true,
            useUnifiedTopology: true
        });

        console.log(`MongoDB Connected: ${conn.connection.host}`.cyan.underline.bold);
    } catch (err) {
        console.log(`Error: ${err.message}`.red);
        process.exit(1);
    }

}

module.exports = connectDB;

Error: option usecreateindex is not supported

Documentation says useCreateIndex is the updated method.

https://mongoosejs.com/docs/deprecations.html#

Jane B.
  • 13
  • 1
  • 4

3 Answers3

1

to me, I just remove useCreateIndex

Ally Ally
  • 26
  • 2
1

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.

0

First, in your project root dir in npm i mongoose command to install Mongoose, then use this code to connect with MongoDB And create a new database.

const mongoose = require('mongoose')

mongoose.connect('mongodb://127.0.0.1:27017/task-manager-api', {
    useNewUrlParser: true,
    useCreateIndex: true
})
David Buck
  • 3,752
  • 35
  • 31
  • 35