How can I verify if "mongoose" is connected to a database

Tell us what’s happening:
I finished the challenge and the app run normally but I couldn’t pass the test it says

“mongoose” should be connected to a database

and I don’t know how to verify if the db is connected ? or the problem is in somewhere else ?

Your project link(s)


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36

Challenge: Install and Set Up Mongoose

Link to the challenge:

Hi @Smaily !

I forked your project and used my credential and was able to pass the test.
You might be experiencing the same issue that this user had.

If you have special characters in your password that might be affecting the tests.

Thanks, I saw that topic before posting my problem and my password is very simple “root” , I want to know if there is any way to confirm the connection between the app and mongo atlas

1 Like

Maybe you could try something like this.

const mongoose = require('mongoose')

//check for connection
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'))
db.once('open', function () {
    console.log('DB connected')

You can see what the console is showing.

I think the code its not working for me or I don’t know what it must show to know that the connection is fine , its already showing a big message without adding the code you provided

I think the problem are the quotes in the URI value.

When I added quotes to my URI value in the secrets tab I got this in the console.

That looks like the same error messages that you are getting.
If you have quotes in the URI try removing them and see if it passes then.

1 Like

Thank you so much It worked ,

The administration should edit the part that says you have to add quotes in the script of the challenge .

It looks like since replit placed the variable in quotes here const mySecret = process.env['MONGO_URI']; you didn’t need to add the quotes to the URI in the secrets tab.

But also, the instructions were written before replit changed to the secrets tab.

If you want to, you can make a separate post in the #contributors section and see if there is interest in revising the directions for replit users.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.