MongoDB and Mongoose - Install and Set Up Mongoose 4.19.2020

Tell us what’s happening:
I’m getting starting on the API’s and Microservices section and setting up MongoAtlas. The MongoAtlas appears to have changed (I never saw a green button in the lower left hand) but after clicking around I eventually worked through the steps and was able to check off all the steps and get the URL to use in the .env file. However, after working through the next set of instructions (even after copying the solution code) the submission fails with the following result.

// running tests “mongodb” dependency should be in package.json (Test timed out) “mongoose” dependency should be in package.json (Test timed out) “mongoose” should be connected to a database (Test timed out) // tests completed

“mongodb” dependency should be in package.json
“mongoose” dependency should be in package.json
“mongoose” should be connected to a database

Your code so far
.env file (with password removed)

reference these in your code with process.env.SECRET

SECRET=
MADE_WITH=
const MONGO_URI=‘mongodb+srv://wvaldes:*****@cluster0-ls0xp.mongodb.net/test?retryWrites=true&w=majority’

// QUESTION: Is the URI supposed to be contained in quotes or not?

package.json

{
“name”: “fcc-mongo-mongoose-challenges”,
“version”: “0.0.1”,
“description”: “A boilerplate project”,
“main”: “server.js”,
“scripts”: {
“start”: “node server.js”
},
“dependencies”: {
“express”: “^4.12.4”,
“body-parser”: “^1.15.2”,
“mongodb”: “^3.0.0”,
“mongoose”: “^5.6.5”
},
“engines”: {
“node”: “4.4.5”
},
“repository”: {
“type”: “git”,
“url”: “https://hyperdev.com/#!/project/welcome-project
},
“keywords”: [
“node”,
“hyperdev”,
“express”
],
“license”: “MIT”
}

myApp.js

/**********************************************

    1. FCC Mongo & Mongoose Challenges
  • ==================================
    *******************************************/
    /
    # MONGOOSE SETUP #
    /
    ================== /
    /
    1) Install & Set up mongoose */

// Add mongodb and mongoose to the project’s package.json. <=Done
// Then require mongoose. <=Done
const mongoose = require(‘mongoose’);
// Store your Mongo Atlas database URI in the private .env file as MONGO_URI.
// Connect to the database using the following syntax:
// mongoose.connect(, { useNewUrlParser: true, useUnifiedTopology: true });
mongoose.connect(process.env.MONGO_URI);

//QUESTION: Should I use { useNewUrlParser: true, useUnifiedTopology: true } or not?

Your browser information:

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

Challenge:
MongoDB and Mongoose - Install and Set Up Mongoose

Link to the challenge:

Link to my Glitch submission:
https://strengthened-fair-shawl.glitch.me as of 4/19/2020

Hi, I’m having the exact same problem! I had an initial snag where I forgot to whitelist the Glitch repository’s IP address with Mongo Atlas, but the issue persists even after I fixed that.

I have noticed something odd, though- when I try to access the “live” version of my project via the url, I just get the Glitch “Starting… To keep Glitch fast for everyone, inactive projects go to sleep and wake up on request.” message and the project never loads. I’m definitely not getting any errors logged in the dev view of the project anymore, though.

I’m wondering if there might be an issue with Glitch itself…?

@wvaldes

MONGO_URI="here is monogdb url" with quote in .env

The connection suggests to use useNewUrlParser and useUnifiedTopology. You can add that like this,

(process.env.MONGO_URI,  { 
useNewUrlParser: true, 
useUnifiedTopology:true
})
1 Like

I ended up literally copy-pasting the freecodecamp “solution” into my package.json, server.js, and .env, changing the MONGO_URI to match my database (yes, the quotation marks are there, and there are no spaces around the equal sign). The only other changes I made to the code were to remove the repository section and the “engines” section from the package.json. (it kept throwing warnings in the logs about “Could not find node 4.4.5, using 10” because 4.4.5 was what was originally specified. Should I have changed it to 10 instead of removing the section wholesale?) My package.json now looks like this:

{
  "name": "fcc-mongo-mongoose-challenges",
  "version": "0.0.1",
  "description": "A boilerplate project",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "express": "^4.17.1",
    "body-parser": "^1.19.0",
    "mongodb": "^3.5.7",
    "mongoose": "^5.9.15"
  },
  "keywords": [
    "node",
    "hyperdev",
    "express"
  ],
  "license": "MIT"
}

Also, I added the useNewUrlParser and use UnifiedTopology to my server.js, which now looks like this:

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

I’m still getting the timeout from Glitch. I have checked that my MONGO_URI string has the correct username and password, and that the current IP of the Glitch project is whitelisted with the correct MongoDB database. There are no new errors in Glitch’s error log since I took out the “engines” section of the package.json. My project is here:
https://brook-regular-contraption.glitch.me/ Any other ideas?

@turningtern

I’ve checked your code. My suggestion is for you to start over the project using the glitch link as instructed here Introduction to the MongoDB and Mongoose Challenges.

Follow the instruction step by step. When you’ll get a new url from glitch o your project, go to package.json, you will see some update suggestion - do it (update) and do not remove anything.

Then follow rest of the instruction - simply it will connect to your database. Remember, do not copy and paste code from elsewhere.

Now just refresh your mind and simply start again.