Option usecreateindex is not supported

I am trying to connect mongoDB to my web app but it is saying that usercreateindex is not supported please help me with this

This is the code from my index.js file

const express = require('express');
const app = express();
const mongoose = require('mongoose');

require('dotenv').config()

const connection_string = process.env.CONNECTION_STRING
//const port = process.env.PORT || 80

app.get('/', (req, res) => {
    res.send("Welcome to our ToDo")
})

app.listen(80,() =>{
    console.log("Server running on port 80.")
})

mongoose.connect(connection_string, {
    useNewUrlParser: true,
    useCreateIndex: true,
    useUnifiedTopology: true

})
.then(() => console.log('MongoDB connection established.'))
.catch((error) => console.error("MongoDB connection failed:", error.message))

this is code from my .env file:

CONNECTION_STRING = mongodb+srv://USER:PASSWORD@cluster0.zzz.mongodb.net/toDoApp?retryWrites=true&w=majority

2 Likes

Did you find a solution to this Ameya? I am at the exact same point.

8 Likes

Welcome to the MongoDB Community Forums @Jose_Valenzuela !

What version of Mongoose are you using? The useCreateIndex option has been deprecated for a while and removed as of the Mongoose 6 release per No More Deprecation Warning Options:

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 .

The solution is to remove any unsupported options from your code.

Regards,
Stennie

31 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.