Tell us what’s happening:
I think I could succesfully connect to the db, created the schema and the model ‘Person’. However, I’m not sure I’m getting the point of the createAndSavePerson function fully.
I’ve read plenty of documentation and even copied and pasted the solution provided to see if it worked but couldnt pass the test. My initial code was already so similar to all the info I found online and got pretty stuck.
Any help is greatly appreciated <3
Your code so far
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
mongoose.connect(process.env.MONGO_URI);
var personSchema = new Schema({
name: String,
age: Number,
favoriteFoods: [String]
});
var Person = mongoose.model("Person", personSchema);
var createAndSavePerson = function(done) {
var budi = new Person({
name: "Budi",
age: 26,
favoriteFoods: ["Shrimps", "Sushi"]
});
budi.save(function(err, data) {
if (err) return done(err);
done(null, data);
});
};
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36.
I never used Glitch before this course, was submitting the live app link successfully until now but receiving a time out on this test.
// running tests
Creating and saving a db item should succeed (Test timed out)
// tests completed
Creating and saving a db item should succeed
Tried submitting the project page link and the code link after your reply and in these cases I do not get a time out but just the plain error:
// running tests
Creating and saving a db item should succeed
// tests completed
Creating and saving a db item should succeed
Maybe I somehow messed up the connection to mongo atlas? I just whitelisted 0.0.0.0/0 on the network settings with no success.
Im starting to suspect my .env file, is this format correct? (these aren’t my real credentials but its in the same format I’m trying with)
Thanks a lot beforehand for the support
EDIT: not sure if relevant, but on my mongo atlas cluster 0 dashboard shows 0 connections to the db