MongoDB and Mongoose - Create and Save a Record of a Model challenge

Tell us what’s happening:
Guys Please i can’t pass this challenge it keeps saying database connection should be present. Anyone who’ve passed this challenge can you help me please? Thanks!

Here is my link.
Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36.

Challenge: Implement the Serialization of a Passport User

Link to the challenge:

1 Like

Hi, Interesting code, learnt quite a lot from it.


  1. Your .env file isn’t hidden,
    I can see your credentials and connect to the cluster if wanted.
    [ It’s not terrible because Atlas has a lot of restrictions, but it would be easy to wipe out your databases ]

  2. Did you test your connection?
    This is how I tested:

First, comment out your main function, and write a simplified one:

async function main() {
    const URI = process.env.MONGO_URI;// Declare MONGO_URI in your .env file
    const client = new MongoClient(URI, { useNewUrlParser: true, useUnifiedTopology: true });
    const a = await client.connect()
    return a

Now run node connection.js

You will find the first bug, I believe.

@dagim The reason why the env file is not hidden, is because you place it in a subfolder. It has to be in the top level.

Hey there mate I really appreciate your help. I found the solution on this link .
Honestly I still don’t know the problem but it passed the solution. Thanks for your help.