Install and Set Up Mongoose issues

Hey having an issue with the first challenge in the Mongo section of Apis and Microservices. My package json looks like this:

{
  "name": "fcc-learn-node-with-express",
  "version": "0.1.0",
  "dependencies": {
    "express": "^4.14.0",
    "body-parser": "^1.15.2",
    "cookie-parser": "^1.4.3",
    "fcc-express-bground": "https://github.com/Em-Ant/fcc-express-bground-pkg.git",
    "mongoose": "^5.2.4",
    "mongodb": "^3.1.1"
  },
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "engines": {
    "node": "4.4.5"
  }
}

but when I run tests, all I get is 3 “Not found” errors. I’m really confused because I get no helpful error messages to show me what is wrong and I’m fairly certain my package.json has the dependencies correct. Any ideas?

2 Likes

Your package.json looks fine. But have you done what’s asked in the rest of the instructions?

Then require mongoose. Store your mLab database URI in the private .env file as MONGO_URI. Connect to the database using mongoose.connect()?

Hey @shimphillip, thanks for the reply.

I believe I have required mongoose correctly. I have this code in myApp.js:

var mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI);

and in my .env file I have included the URI:
MONGO_URI=‘mongodb://:@ds018248.mlab.com:18248/apimicroservices’

This line looks bit off to me. You shouldn’t wrap the value with quotes. You also need to give user Id and password as part of the string.

Mine looks like this.

MONGO_URI=mongodb://shimphillip:myPassword@ds135441.mlab.com:35441/shimphillip

Ok so after I formatted my URI to look like yours (removed the quotes and added userid and password of db on mlab) my test still fails. What’s weird is that I feel like 2 of the tests should still pass even if the URI was incorrect (if it’s looking for the mongoose and mongodb dependencies in my package.json why would those tests fail?) Not sure how to proceed at this point.

I have the same problem. It came out that I didn’t fork the fcc initial proj.

I’m facing the same issue. Looks like an authentication error but I can’t tell whats wrong.

I think that’s my issue to: from what I can tell there is no link on the intro pages for that project I started modifying my earlier project from the express section. There is a link to mLab but no link to the glitch project boilerplate for the mongo challenges

Update: Never mind , the link is there on the last bullet point of the first section of the intro to the database excercises.

I had the same issue and solved it this way:

  1. I used these versions
    “mongoose”: “^5.1.6”,
    “mongodb”: “^3.0.10”

  2. MONGO_URI=mongodb://myUser:myPassword@ds155653.mlab.com:55653/rashadd
    *there should be no spaces between “=” operator

Here in my Database in the “Users” tab I checked “Add database user” and added a new user and a new pass. I used this username and pass for connection in Glitch project and problem was solved

I was having this issue, my MONGO_URI looked like this:

mongodb+srv://user:<password>@cluster0-bwc5q.mongodb.net/test?retryWrites=true&w=majority

I removed the last bit so I left it like this:

mongodb+srv://user:<password>@cluster0-bwc5q.mongodb.net

It worked after that

3 Likes

This code fixed the issue for me
.env

MONGO_URI='mongodb+srv://<username>:<password>@cluster0-<db-name>.gcp.mongodb.net'

.package.json

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

myApp.js

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

A post was split to a new topic: Installing and Setting Up Mongoose

As this thread is old/outdated, I have closed it. If you have come across this thread, and want help with your own code/project, I suggest you open your own topic for help.

1 Like