Mongoose insertMany().exec() returning a TypeError Mongoose insertMany().exec() returning a TypeError mongoose mongoose

Mongoose insertMany().exec() returning a TypeError


As it's explained in the reference, exec() may be needed for methods that return queries because queries are not promises. The reference also lists methods that return queries:

Model.deleteMany()Model.deleteOne()Model.find()Model.findById()Model.findByIdAndDelete()Model.findByIdAndRemove()Model.findByIdAndUpdate()Model.findOne()Model.findOneAndDelete()Model.findOneAndRemove()Model.findOneAndUpdate()Model.replaceOne()Model.updateMany()Model.updateOne()

insertMany isn't one of them, it returns a promise right away.

It should be:

function insertNewResults(data) {    return Model.insertMany(data);}