Created and Saved a Record of a Model but the tests still won't pass

Hi all,
I seem to be getting the following error shown after the freecodecamp checks, as many others when trying to complete this challenge on repl.it as many others have:

// running tests
Creating and saving a db item should succeed (Test timed out)
// tests completed
Your project link(s)

I do not understand how the test is run as I can see the correct entry in the database but the fcc check doesn’t seem to recognize it.

I double checked that the database is accessible by all as ensured in the provided setup steps and also tried a few of the fixes others mentioned (i.e. removing the flags in the connect method, not having special characters in password, cleaning the collections, changing dbname etc.) but no luck with passing the tests.
*Also thinking this could be a server error if too many people are trying to run things on fcc but I don’t know.

Any help would be much appreciated.

my repl.it solution: boilerplate-mongomongoose - Replit

or as code:

 require('do> tenv').config();
 let 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]
 });
 
 let Person = mongoose.model('Person', personSchema);
 
 const createAndSavePerson = (done) => {
   const jamesBond = new Person({
     name: 'James Bond',
     age: 12,
     favoriteFoods: ['kebap', 'corba', 'kisir', 'pizza', 'burger']});
   jamesBond.save(function(data,err) {
     if (err) return console.error(err);
     done(null, data);
   })
 };

Your browser information:

User Agent is: Chrome/110.0.0.0

Challenge: MongoDB and Mongoose - Create and Save a Record of a Model

Link to the challenge:

I fixed the issue, turns out that I was ordering the err and data arguments in the callback function in the save method under createAndSavePerson() in the wrong order, should have been function(err,data) instead of function(data,err). Changing the order fixed the issue.

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