"mongoose" should be connected to a database

Tell us what’s happening:

Hello I get the error message here:
“mongoose” should be connected to a database

I believe the problem is in my link:
mongodb+srv://Annie:@cluster0-6z8hh.mongodb.net/?retryWrites=true&w=majority

The message from mongoDB is: Replace with the password for the Annie user. Replace with the name of the database that connections will use by default.

I cannot find the dbname that they ask me to insert. What can I do?

Your code so far

“dependencies”: {
“express”: “^4.17.1”,
“body-parser”: “^1.19.0”,
“mongoose”: “^5.9.1”,
“mongodb”: “^3.5.2”
},

and this in app.js:

const mongoose = require(‘mongoose’);
mongoose.connect(process.env.MONGO_URI,{ useNewUrlParser: true, useUnifiedTopology: true });

Your browser information:

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

Challenge: Install and Set Up Mongoose

Link to the challenge:

Have you solved it? I also got the same error and stuck in the “mongoose” should be connected to a database.

1 Like

I had the same problem + authentication error. So my advice is to be sure that when you create a user in Database Access, provide user name which is NOT the same as you user account which you connect to MongoDB atlas.

mongodb+srv://<username>:<password>@cluster0.bixmj.mongodb.net/myFirstDatabase?retryWrites=true&w=majority