2 FCC projects connects to mongodb, one success, the other failed

I’ve done 2 projects from freecodecamp that requires me to connect to mongodb from glitch. One success, while the other failed. I used the exact same credentials (username & password), in both the working one and the failed one. Then I tested the connection with mongoose.connection.readyState, the success one resulted in 2, while the failed one is 0 (zero), which indicates failure.

What was the error message on the failed connection?

The cause of the error is likely due to the package versions in package.json, hulking-thursday has older versions of mongodb and mongoose, so would need either a slightly different connection string, or different connection options. The error message should tell more about this.

A security tip for Glitch projects …

process.env.MONGO_URI should be a derived value rather than setting it. The connection string should be put into a file called .env like this:


Then you will be able to share your code without exposing the connection details to public.

Once you do this, change the mongo username and password, as they have already been exposed.

As per suggested by a fellow FCC member, i change the connection to mongoose.connect(process.env.MONGO_URI, { useMongoClient: true });
and i remove +srv from my connection string