MongoDB and Mongoose - Create a Model

Tell us what’s happening:
Describe your issue in detail here.
I tried almost all the variations to create a basic mongoose model. The code that I pasted below was also tested by me in a local Node express application, which worked perfectly fine and a collection was created in Mongoose. But the same code won’t work in replit. Mongoose connects successfully, but the schema is not created. I did not changed server.js file, neither package.json. I also tried updating the packages, but didn’t work.

Your code so far

const mongoose = require(‘mongoose’);

mongoose.connect(process.env.URI, { useNewUrlParser: true, useUnifiedTopology: true }).then(() => console.log(‘Server Running’)).catch((error) => console.log(error))

let Person;

const personSchema = new mongoose.Schema({
name: { type: String, required: true },
age: Number,
favoriteFoods: [String]
Person = mongoose.model(“Person”, personSchema);

Your browser information:
Microsoft Edge

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

Challenge: MongoDB and Mongoose - Create a Model

Link to the challenge:

@DaniyalKhan welcome to the community forum! :wave:

Do you have screenshot of errors from the console on replit?

Hi there!
Thank you for the response. The error was not resolved. Although I deleted the current replit working directory, and again started from scratch, and I didn’t see the error again.
Adding to this, I did not make any changes in configurations or server.js file. I don’t know why this error come up, but freecodecamp did not pass the testcases even when I copy pasted the solution provided below the challenge.

in my limited experience, sometimes replit gets glitchy. (not an expert)

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.