Tell us what’s happening:
Describe your issue in detail here.
The database connection test doesn’t pass, even though i used a try...catch block and used console.log() to check if the connection is successful.
The database i’m trying to connect to in the URI is called “myFirstDatabase”, it exists on my Mongo Atlas account, in case that’s important. But also, i tried changing this code: await client.db('database').collection('users')
to this: await client.db('myFirstDatabase').collection('users')
But the db connection test still did not pass.
According to the message in the console, the connection does happen. Please lend me a hand. Thank you
Yeah, i tinkered with it for a while, that’s why you got that error, probably.
Anyway, i removed this piece of code that’s outside and after myDB(async client =>... db connection function:
At the same time, inside the myDB(async client =>... db connection function,
there’s this piece of code:
app.route('/').get((req, res) => {
//Change the response to render the Pug template
res.render('pug/index.pug', {
title: 'Connected to Database',
message: 'Please login'
});
});
Which basically gets ignored, cause the one from outside comes after it.
It seems like the tests check the existence of a db connection against this data from the frontend:
{
title: 'Connected to Database',
message: 'Please login'
}
which is a bit weird to me, cause the connection was there, but the test was designed to look for these title and message and not the connection itself.
Anyway, that’s what solved it for me.