Tell us what’s happening:
I am stuck on this task.
I already changed my code a few times and it seemed correct but every time i try to submit it an error occurs “Test Timed Out”.
Already tried different browsers (Edge,Chrome,FireFox,Opera) but it’s always the same error. I can’t seem to fix it.
I tried to solve it locally via VSC and CMD but that didn’t work either
I tried to find solutions online but there are no videos etc. of running this task locally
Would really appreciate any help.
My Code:
require(‘dotenv’).config();
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: { type: Number, required: true },
favoriteFoods: { type: [String], required: true }
});
const Person = mongoose.model(‘Person’, personSchema);
function createAndSavePerson(name, age, favoriteFoods) {
const Tom = new Person({
name: “Tom”,
age: 20,
favoriteFoods: [“apple”]
});
Tom.save(function(err, savedPerson) {
if (err) {
console.error("Fehler beim Speichern der Person:", err);
} else {
console.log("Person erfolgreich gespeichert:", savedPerson);
}
});
}
###Your project link(s)
solution: https://37f38068-cf3d-4319-a6f6-8e4f7497e604-00-145cxrtyzo4ok.kirk.replit.dev
Challenge Information:
MongoDB and Mongoose - Create and Save a Record of a Model