MongoDB and Mongoose - Create and Save issue

MongoDB and Mongoose - Create and Save issue
0

#1

I am getting Missing callback argument error

Here is my work


var createManyPeople = function(arrayOfPeople, done) {
    const person = new Person({name:"Joe",age:"20",favoriteFoods:["rice"]})
    person.save(function(err,data){
      if(err){
        done(err);
      }
    done(null, data);
    });    
};

Can anyone help me find what I am missing out


#2

When you defined done did you put the second parameter as optional? If not you’re calling done(err) without the second argument, hence the Missing callback argument error^^


#3

For createManyPeople you should be using the Model.create method (see https://mongoosejs.com/docs/api.html#model_Model.create)