I've checked around Stack and the Mongoose docs for this, but I can't seem to get it right. As implied in the title everything was fine until i upgraded the packages for mongoose and connect-mongo.
Here's my database.js:
var mongoose = require('mongoose');
var mongodbUri = require('mongodb-uri');
function encodeMongoURI (urlString) {
if (urlString) {
var parsed = mongodbUri.parse(urlString)
urlString = mongodbUri.format(parsed);
}
return urlString;
}
mongoose.connect(encodeMongoURI(process.env.MONGODB_URI) || 'mongodb://localhost:27017/goGradesDB',//specifies goGradesDB as the db to use locally
{
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true,
}).catch(error => handleError(error));
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
module.exports = db;
After looking over the docs in mongoose and searching this site I've tried the following:
- installed the mongodb-uri package to parse the uri (although I'm not sure if that's needed for the local db. I can't get onto my heroku db either, but that's something I'm working with support on.
- added the "useNewURLParser", etc. tag.
- added the port number into the local db address
- added the catch onto the end of mongoose.connect
Despite this I keep getting the following error output in my terminal and the db times out whenever I try to login to the app. Here's the output:
"The server is running on port 3000!
(node:71951) UnhandledPromiseRejectionWarning: MongoParseError: URI malformed, cannot be parsed"
and later,
"(node:71951) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:71951) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code."
Any insight would be much appreciated. Thank you!