UPDATE: THE MAIN ISSUE OF THIS TOPIC IS RESOLVED - issue was because I was not using the arrayOfPeople variable. At least, that’s what seems to be the case - there was no error specifying it but I noticed that variable after the fact and when I made use of it the lesson passes along with the tests. However, I am curious about us passing in a callback to create() when the documentation does not state it as a parameter, not even an optional one: (Mongoose v8.0.3: Model)
I have completed this lesson and all the tests complete:
// running tests
Creating many db items at once should succeed
// tests completed
However the lesson does not pass. I have tried many different ways of completing the challenge, see various code attempts below:
const createManyPeople = (arrayOfPeople, done) => {
const people = [
{
name: 'Jane',
age: 28,
},
{ name: 'Chloe',
age: 32,
favoriteFoods: ['apples']
},
{
name: 'Alan',
age: 25,
favoriteFoods: ['buns']
}
];
/*
Person.create(people)
.then((data) => {
console.log('success, data: ' + data);
done(null, data);
})
.catch((err) => {
console.log('error: ' + err);
done(err);
});
};
*/
/*
Person.create(people, (err, data) => {
if(err) {
console.log(err);
done(err);
} else {
done(null, data);
}
});
*/
Person.create(people, function (err, data) {
if (err) return console.log(err);
done(null, data);
});
};
The last attempt there was taken directly from a post about the solution to the lesson. I can provide more of the code if necessary.
I really don’t understand what is going on, the tests complete. I figure the first attempt there with the .then() should work since create() returns a promise, and again the tests pass but the lesson doesn’t succeed. I tried the approach where we pass a callback to create() even though the documentation for create() does not say that it takes a callback (Mongoose v8.0.3: Model) but I get the same results - tests pass but lesson doesn’t.