MongoDB and Mongoose - Install and Set Up Mongoose

Has anybody tried this recently? I can’t connect to Mongoose. Getting the following error:
(node:14936) UnhandledPromiseRejectionWarning: MongoNetworkError: connection 3 to fcc-shard-00-00-vcnna.mongodb.net:27017 closed

It passes the first 2 tests which are that mongodb and mongoose are in the dependencies. Also, the instructions are outdated, as mlab is now mongodb Atlas and the current uri looks like this:

mongodb+srv://mscanza:password@fcc-vcnna.mongodb.net/test?retryWrites=true

Could this be why it is not able to connect to Mongoose?

1 Like

FCC: mlab is no longer accepting new users. Does this mean these challenges can no longer be completed? Can you please look into this?

1 Like

@mscanza, I’ll do a test run later this evening, if no one hasn’t got to it by then…

im having the same issue as user @mscanza. That you have to use Mongo Atlas meaning i can’t follow the instructions in the challenge. Does anyone know when the (apis-and-microservices) challenges will be updated or a quick fix to be able to complete the challenge? Thank you.

1 Like

I have just confirmed that the lessons still work even after the changes made from the acquisition of mlab by mongodb, these instructions need to be fully changed however, I will look to submitting a PR or see if one hasn’t already been submitted.

But, it should not stop anyone from continuing with the lessons, since the instructions in MongoDB Atlas are pretty clear, see below for brief instructions or go to this link for a more detailed set of instructions from a PR of the lesson that is pending approval.

  1. Create your MongoDB Atlas account.
  2. As soon as you login, it will walk you through building your first cluster - may take a few minutes to complete.
  3. Then following the green tab in the bottom left of the screen, click on Create your first database user, follow the instructions and create a user with a password.
  4. In the same green Get started tab click on Whitelist your IP address, warning here, glitch will not connect if you don’t allow all IP addresses, which is what I did for it to work.
  5. Click Connect to Your Cluster > click connect in the sandbox window, and then click connect your application in the pop up window, then copy the connection string, and paste it in your .env file in glitch and substitute the password you provided in step 3 for the <password> area , and you are good to go. Test the first lesson and it should pass.

Update
mongoDB Atlas says it requires MongoDB version 4.0 for the free tier clusters . If you are using Mongoose, this means that you would need mongoose > 5.2 to have a compatible mongoDB driver that Atlas can use

Submit the link to your LIVE page from glitch for the challenge to pass and not the link to your glitch editor

11 Likes

Thank you Dereje1 this was extremely helpful. Whitelisting all ip addresses fixed it.

Hi Team,

I cannot establish connection to database.
My code:
.env file

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

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.16.4”,
“body-parser”: “^1.18.3”,
“mongoose”: “^5.4.19”,
“mongodb”: “^3.1.17”
},
“engines”: {
“node”: “4.4.5”
},
“repository”: {
“type”: “git”,
“url”: "
},
“keywords”: [
“node”,
“hyperdev”,
“express”
],
“license”: “MIT”
}
Please help!!!

My console output

I forgot to mention. I’m on Ubuntu 16.04.

see here first: MongoDB and Mongoose - Install and Set Up Mongoose

1 Like

Thanks for the reference Dereje1. I’m a little bit confused here. I tried to change dependencies version and it did not work out. If you know the trick, please tell…

Did you whitelist all ip addresses in MongoDB atlas as pointed out in the link I gave you ?
If you followed the instructions I posted above and still can’t get it to work post your glitch link and i’ll look into it

Hey Dereje1,
I think all steps suggested in your links were taken. IP addresses where white listed.

.

Here is a link to my Glitch.
ttps://glitch.com/edit/#!/orchid-purple?path=.glitch-assets:1:0
Great thanks in advance

If you click on allow all ip addresses you should see 0.0.0.0/0 (includes your current IP address) included in your ip address list, which means you may not have done it correctly. Your glitch app connects fine for me with my own connection string…

2 Likes

Thank you Good Sir. It’s working fine now.

good, I have merged your thread to the main one

Hi, I’ve encountered an issue with this exercise. I believe my code is correct, however when I submitted my solution, all the tests failed, and I saw this error message on the Chrome console:

“Access to XMLHttpRequest at ‘/package.json’ from origin ‘’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.”

Does anyone know how I can fix this?

thanks for the tip on allowing all ip addresses on glitch, i was running around in circles trying to figure out why it wasnt working!

thank you … i got stuck in the lessons instructions …