Minh Tuấn Ngô
Minh Tuấn Ngô

Reputation: 11

How to fix MongoParseError: option usecreateindex is not supported?

I have this code and have problem with Mongo version. Help me to fix this code, please. Thanks!

const connectDatabase =( )=>{

    mongoose.connect(process.env.DB_URI,{useNewUrlParser:true,useUnifiedTopology:true,useCreateIndex:true}).then(()=>{
        console.log(`Mongodb connected with server: ${data.connection.host}`);
    }).catch((err)=>{
    console.log(err)
    })

}

Upvotes: 1

Views: 2077

Answers (1)

mohammad Naimi
mohammad Naimi

Reputation: 2359

downgrade to mongoose v5 or remove this option set useCreateIndex to false

 mongoose.connect(process.env.DB_URI,{useNewUrlParser:true,useUnifiedTopology:true,useCreateIndex:false}).then(()=>{
        console.log(`Mongodb connected with server: ${data.connection.host}`);
    }).catch((err)=>{
    console.log(err)
    })

Upvotes: 2

Related Questions