Mongodb and mongoose(Create a Model)

Tell us what’s happening:
Describe your issue in detail here.
… please check let me know where the error is
everything seems fine on glitch but am not passing the challenge.

Your project link(s)

solution: Glitch :・゚✧

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0

Challenge: Create a Model

Link to the challenge:

Why did you write your code after the exports?

The directions say
DO NOT EDIT BELOW THIS LINE

Try moving your code up to the top and see if it works then.

… I moved the code up still not working…

When I run your code in replit, I get an error message saying that Person is already defined.

FCC already provided you with this variable let Person so there is no need to create a new one

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

You should just assign the model to the variable that was already there and it should pass.

…i can’t fingure out what you mean please am lost now.
eg?

If you look at the starter code, you will see there is already a variable declared for you at the top.

require("dotenv").config();

let Person;

You just need to assign the model to that variable like this.

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

Make sense?

One last thing,
Move all of this to the top

const mongoose = require("mongoose");
mongoose.connect(process.env.MONGO_URI, {
  useNewUrlParser: true,
  useUnifiedTopology: true
});
const personSchema = new mongoose.Schema({
  name: { type: String, required: true },
  age: Number,
  favoriteFoods: [String]
});

Reason being is because you need to have the import statement, mongoose connection and then the schema before the model or else it can’t access it.

Your first few lines of code should look like this.
EDIT:

//import dotenv library
//import mongoose library
//then do mongoose.connect
// then create the personSchema
//then create the model

When I tested your code earlier, I moved it up but forget to mention that in the reply.
Sorry about that. :grinning:

That is what I meant by this part here

…i use the terminal to import the dotenv library and mongoose library but still not working am totally confused ,please can you send the copy of your solution earlier let learn from that?thanks…

I just test your code and it passes for me.

Are you sure you are using the correct link?
You should test it with the live link.
https://succinct-tropical-papyrus.glitch.me

…Am very greatful for your support…