Tell us what’s happening:
Hey guys, I’m trying to figure this out myself but with no sucess. When I do this:
var arrayOfPeople = [
{ name: "Kafka", age: 23, favoriteFoods: ["ham"] },
{ name: "Pedro", age: 33, favoriteFoods: ["apple"] },
{ name: "Rita", age: 13, favoriteFoods: ["cake"] }
];
var createManyPeople = function(arrayOfPeople, done) {
Person.create(arrayOfPeople, (err, data) => {
if (err) return console.error(err);
done(null, data);
});
};
even though I am able to pass the challenge, the data doesn’t get inserted into the mongodb database. However, when I try a silly test like this:
var arrayOfPeople = [
{ name: "Kafka", age: 23, favoriteFoods: ["ham"] },
{ name: "Pedro", age: 33, favoriteFoods: ["apple"] },
{ name: "Rita", age: 13, favoriteFoods: ["cake"] }
];
var createManyPeople = function(arrayOfPeople, done) {
/*Person.create(arrayOfPeople, (err, data) => {
if (err) return console.error(err);
done(null, data);
});*/
};
Person.create(arrayOfPeople); //The same way I found on Mongoose documentation
the data does get inserted normally into to the db. It seems to me that there is something wrong with the createManyPeople()
and done()
functions.
Link to the challenge:
https://www.freecodecamp.org/learn/apis-and-microservices/mongodb-and-mongoose/create-many-records-with-model.create