Error creating an instance from a mongoose schema

Hi all,

I need some help, I’ve been stuck for too long now on the MongoDB and Mongoose - Create a Model challenge,
I really don’t understand what I’m doing wrong here, thanks a lot for your help :slight_smile:

This is my code:

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

const Schema = mongoose.Schema;

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

const Person = mongoose.model("Person", personSchema);

This is my glitch link to the challenge:
https://glitch.com/edit/#!/ambiguous-farmhouse?path=myApp.js:45:0

Hi @camperextraordinaire
I just updated the link, hopefully it works now

Thanks @camperextraordinaire for looking into it, good to know that the code should work with a valid URI.

So, I tried again, created a new cluster, got a new URI , but it still doesn’t work.

My URI looks like this:

mongodb+srv://joe-messi:myPassword@cluster0-uu0xc.mongodb.net/test?retryWrites=true&w=majority

and the .env file looks like this:

MONGO_URI='mongodb+srv://joe-messi:myPassword@cluster0-uu0xc.mongodb.net/test?retryWrites=true&w=majority'

Any thoughts ?
thanks for the help

I literally have no idea what I’m doing wrong. I spent more than 7 hours now trying to fix this.
Is there something you have to do before the cluster will start to work ? or just copying the string provided will do ?

yes I did, I spent a few hours chatting with someone from MongoDB Atlas and we realised that the connection URI is just fine, we created an instance of a Person and we saw it added to the collection of the cluster in the Atlas web site, so the connection fine, there must be another problem or something I’m missing that the freecodecamp validation doesn’t like, but I’m leaving it like that now, I will continue with the lessons and hopefully this won’t effect future validation.
Thanks for your help

Hi @camperextraordinaire, apparently now when I submit the glitch url for submission everything is fine, I didn’t change anything from yesterday and I’m doing exactly the same thing I did yesterday, but now, this morning, it’s working, I don’t know what to say, I spent the whole day trying to fix something that wasn’t broken I guess, probably something to do with the browser ??? oh well, good that now it’s working and I can continue with the lessons in peace :slight_smile: thanks again for looking into this with me.