mongoose: throw new MongooseError('The `uri` parameter to `openUri()` must be a string)

i just configured my new project and added mongoose and as it seems new release 5.7.4 has a bug in it because of when i use code like this:

require('dotenv').config({
     path: '../.env' 
})
const mongoose = require('mongoose');
console.log(process.env.MONGO_URI)
mongoose.connect(process.env.MONGO_URI, {
    useNewUrlParser: true,
    useCreateIndex:true,
    useFindAndModify: false,
    useUnifiedTopology: true
 })
 .then(()=>{
    console.log('con to db established')
 })
 .catch(err=>{
    console.log(`db err: ${err.message}`);
    process.exit(-1)
 }) 
 const schemas = require('./schemas');
 const models = {};
 for(let i in schemas){
    models[i] = mongoose.model(i, schemas[i]); 
 }
 //exporting modules

it logs error in title even tough when i log process.env.MONGO_URI it logs correct value and when i add url straight into mongo.connect() like this "mongodb+srv://MYUSERNAME:MYPASSWORD@<CLUSTER>.mongodb.net/MYDBNAME?retryWrites=true&w=majority" it still logs same, how can i fix it? i am saying that is is 5.7.4 release bug because i have other project initialized with mongo ^5.7.3 and it is not logging this + i have this code in that project for generating models and connection

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19

Most upvoted comments

@fktmjohn1 surprisingly I solve the error on my end let me know if your still having issues even thou we might be working on completely different projects.