Unhandled promise rejection: Error: URL malformed, cannot be parsed

Mongoose 5.x supports following syntax for authorization and also make sure you have not used any special character in url like @,-,+,>

mongoose.connect(MONGO_URL, {
  auth: {
    user: MONGO_DB_USER,
    password: MONGO_DB_PASSWORD
  }
})

Or if you want to remove deprication warning Avoid “current URL string parser is deprecated”

Add option useNewUrlParser

mongoose.connect(MONGO_URL, {
  auth: {
    user: MONGO_DB_USER,
    password: MONGO_DB_PASSWORD
  },
  { useNewUrlParser: true }
})

Leave a Comment