Cannot pass "MongoDB and Mongoose - Create a Model" challenge

Tell us what’s happening:
Greetings,
before you ask, yes, I’ve already searched all over the forums and internet in hope to figure out why my code is not working, I’ve triple checked everything and it’s still not letting me pass the challenge. I’m smashing my head over this challenge for a week now… Mongo URI is correct and I can connect to it with Compass without any problems.

Your code so far

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

var Schema = mongoose.Schema;
var personSchema = new Schema({
  name: {
    type: String,
    required: true
  },
  age: Number,
  favoriteFoods: [String]
});

var Person = mongoose.model('Person', personSchema);

Challenge: Create a Model

Link to the challenge:

Just a question, if you do

console.log(process.env.MONGO_URI)

Does the URI show? I assume you’re using Glitch and Glitch would just not accept the URI for me as an environment variable, and would keep returning undefined.

I tried replacing the process.env.MONGO_URI with my actual URI, but it still doesn’t work.

Can you provide a link to your Glitch Project?

What’s your URI? (with password removed ofc)

mongodb+srv://user:pass@cluster0.ewpvv.mongodb.net/test?retryWrites=true&w=majority

Go to Tools > Logs
Do you get this error?

I don’t see that anywhere.

Are there any errors at all in Glitch Logs?

None from what I can see.

When I replaced it with my URI it passed the challenge, so the issue might be with your database access.
Have you allowed access from all IP addresses in MongoDB atlas?

This is in my network access:

Can you create a User for me for your database and PM me the username and password so that I can try and connect to it?

Sure thing, I sent it to you.

I just put the URI you sent me into the connect method and it seems to work:

const mongoose = require("mongoose");
mongoose.connect('mongodb+srv://fcc_temp:password@cluster0.ewpvv.mongodb.net/test?retryWrites=true&w=majority', { useNewUrlParser: true, useUnifiedTopology: true }); 
1 Like

Looking at your URL, this is exactly where the issue was.
Doesn’t work:
https://glitch.com/~possible-jumbled-chocolate

Works:
https://possible-jumbled-chocolate.glitch.me

Thanks a lot for help, it passed with that one now. A strange thing is that I used the first URL in the first challenge and it worked, but not with the second one.

1 Like

Wow! I can’t believe that was the issue. Glad you got it sorted.
If there’s nothing else, could you mark this as solved?

Sure thing, how can I do that?