Tell us what’s happening:
Describe your issue in detail here.
I keep running into an error that collection.remove is depracted. Here is the code i have for the create many people function :
const createManyPeople = (arrayOfPeople, done) => {
var arrayOfPeople = [{name:‘Merissa’, age:23, favoriteFoods: [‘Strawberries’]}, {name:‘Audrey’, age: 20, favoriteFoods: [‘Salad’]}, {name: ‘Wendy’, age: 42, favoriteFoods: [‘wine’, ‘burgers’]}
]
// create people objects at once
var createPeople = function(arrayOfPeople, done){
Person.create(arrayOfPeople, function(err, people){
if (err) console.log(err)
done(null, people)
})
}
};
any idea on how to use the other delete method instead?
IF u wanna use create method with an array… then u would need to iterate the array and pass one by one each element to that method
…
on the other hand… IF u wanna pass the whole array to create all those documents at once… then u will need to use ANOTHER method insertMany according to the documentation
…
correction: https://mongoosejs.com/docs/api.html#model_Model-create
create accepts an array as parameter
You can ignore the deprecation warning it just means in future versions of the library it may be removed. It’s basically just to give the developer a head start to change code as needed for use with future versions of the library.
arrayOfPeople is passed to the createManyPeople function for you. You then pass it to the Person.create() method as the first argument before the callback (remember to do the done song and dance inside the callback).