'Mongoose Error: "useCreateIndex" is not supported but documentation still has it
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.
Solution 1:[1]
to me, I just remove useCreateIndex
Solution 2:[2]
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
})
Solution 3:[3]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ally Ally |
Solution 2 | David Buck |
Solution 3 | Midzo Bagira |