I am having issues with my simple node express app when trying to connect to MongoDB atlas. Despite deleting node_modules and re-downloading all packages, I am still encountering the same error.
The specific error message reads as follows: Cannot read properties of undefined (reading 'constructor').
My approach involves importing mongoose at the start of the page using this command:
import mongoose from 'mongoose'
Additionally, below is the snippet for my connection function:
const connectToMongo = async () => {
try {
await mongoose.connect(process.env.DATABASE_URL as string, { autoIndex: true, dbName: 'personal-blog' });
console.log('connected to MongoDB');
} catch (error) {
console.log('error connection to MongoDB:', error.message);
}
};