Install and Set Up Mongoose - Getting status 1

Install and Set Up Mongoose - Getting status 1


I’m using these versions

"mongoose": "4.13.17",
"mongodb": "~3.1.13"

for this boilerplate

This is my connection code

var mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI, { useMongoClient: true, });

and I’m checking the connection with this line-


And I get status 2 (connecting) And it doesn’t connect. What am I doing wrong?


I can’t be sure why you’re not connecting without seeing the rest of the code, but this is an asynchronous operation so console.log(mongoose.connection.readyState); will display before mongoose.connect(process.env.MONGO_URI, { useMongoClient: true, }); has actually connected.
If you put a console.log(mongoose.connection.readyState); as a callback to a function within mongoose.connect as in:
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true }, function(){console.log(mongoose.connection.readyState);});
then it will give a different value (1), if all goes well.


Thank you, that indeed helped get the actual status which is not connected (1)
I´m just using the whole boilerplate for the challenge, with that line to connect to the Db.


Solved. the user db was having a - and the app wouldn’t connect (although, mlab won’t prevent to create it that way)