MongoDB und Mongoose - Create and Save a Record of a Model

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 but that didn’t work either :confused:
I tried to find solutions online but there are no videos etc. of running this task locally :confused:

Would really appreciate any help.
I decided to change the code a bit and even up the time-out limit but still no success :confused:
I tried everything and seriously don’t know what else to do…

require(‘dotenv’).config();

const mongoose = require(‘mongoose’);

mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
connectTimeoutMS: 30000, // Timeout für die Verbindung: 30 Sekunden
socketTimeoutMS: 45000 // Timeout für Datenbankoperationen: 45 Sekunden
});

const Schema = mongoose.Schema;

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

});

let Person = mongoose.model(“Person”, personSchema);

const createAndSavePerson = (done) => {
let Tom = new Person({
name: “Tom”,
age: 20,
favoriteFoods: [“apple”]
});

Tom.save(function(err, data) {
if (err) {
return console.error(err);
}
done(null, data);
});
};

Challenge Information:

MongoDB und Mongoose - Erstellen und Speichern eines Datensatzes für ein Modell

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