beaucarnes / mern-exercise-tracker-mongodb

MERN exercise tracker - code for tutorial
695 stars 626 forks source link

can't connect to mongoDB atlas #6

Open tinkerFAUJ opened 4 years ago

tinkerFAUJ commented 4 years ago

hi thanks a lot for a great tutorial. I am new to nodejs and the whole mern stack. I have executed the code as instructed but the connection to mongoDB atlas is not working. The confirmation string about the successful connection is displayed on the console. also the mongoDb cluster dashboard does not show any connections

utshomomen commented 4 years ago

I have the same problem.

dacicus75 commented 4 years ago

I added mongodb dependency to backend, and also used whole driver for connection

nhargho commented 3 years ago

Can you please explain the process in a elaborated way, I'm having the same issue. Thanks.

dacicus75 commented 3 years ago

Added mongodb dependency to package.json file for backend.

db connection in server.js

const uri = process.env.ATLAS_URI; mongoose.connect(uri, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true } ); const connection = mongoose.connection; connection.once('open', () => { console.log("MongoDB database connection established successfully"); })

const tasksRouter = require('./routes/tasks'); const usersRouter = require('./routes/users');

app.use('/tasks', tasksRouter); app.use('/users', usersRouter);

app.listen(port, () => { console.log(Server is running on port: ${port}); });