"mongoose" should be connected to a database error

Hello!

I am having problems connecting my repl.it to the mongoose db I created with the tutorial “get-started-with-mongodb-atlas”

Here is the dependencies section of my package.json:

"dependencies": {
        "body-parser": "^1.15.2",
        "dotenv": "^8.2.0",
        "express": "^4.12.4",
        "mongodb": "^3.0.0",
        "mongoose": "^5.6.5"

Here is the top of myApp.js:

require('dotenv').config();
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true });

and here are the errors I’m getting in the console:

 npm start

> fcc-mongo-mongoose-challenges@0.0.1 start /home/runner/boilerplate-mongomongoose
> node server.js

Your app is listening on port 3000
(node:678) UnhandledPromiseRejectionWarning: MongoError: bad auth : Authentication failed.
    at MessageStream.messageHandler (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/cmap/connection.js:272:20)
    at MessageStream.emit (events.js:314:20)
    at processIncomingData (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
    at MessageStream._write (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
    at doWrite (_stream_writable.js:403:12)
    at writeOrBuffer (_stream_writable.js:387:5)
    at MessageStream.Writable.write (_stream_writable.js:318:11)
    at TLSSocket.ondata (_stream_readable.js:718:22)
    at TLSSocket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at TLSSocket.Readable.push (_stream_readable.js:213:10)
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:188:23)
(node:678) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:678) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Any help would be appreciated!

Your project link(s)

solution: https://replit.com/@okaykaylyn/boilerplate-mongomongoose

Your browser information:

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

Challenge: Install and Set Up Mongoose

Link to the challenge:

Hello there,

What do you see, when you console.log(process.env.MONGO_URI)? Remember: do not share the your DB password on the forum.

After the errors show in the Repl.it console? When I enter that into the Repl.it console, nothing happens. When I use my chrome browser console, it’s undefined.
It’s probably worth noting that I was not able to make an .env file in Repl.it, but instead had to use their “Secrets” editor on the side pane, though I don’t think that would have caused the issue.

Before. You need to ensure what you are passing to this is correct:

VM106:1 Uncaught ReferenceError: process is not defined
    at <anonymous>:1:13

^ is what shows in the chrome console.
In Repl.it, though, my secret is defined as such in the raw secrets editor (except with an actual password):

{
  "MONGO_URI": "mongodb+srv://okaykaylyn:<password>@cluster0.vc93y.mongodb.net/db0?retryWrites=true&w=majority"
}

Try it without the quotes and see if it works then.
Screen Shot 2021-06-13 at 11.34.59 AM

Try removing any mention of dotenv in your app - uninstall it, and do not require it.

Unfortunately, this didn’t make a difference.

Removed from Package.Json, and removed the required line at the top of myApp.js. Did not find any other references. Still having the same issue. :confused:

I figured out the issue.
My db password ended in a special character, which Mongo allowed, but which was not jiving well with everything else. I changed the password to only contain letters and that solved the problem.

2 Likes

I appreciate your help and patience though, @Sky020 and @jwilkins.oboe !

1 Like