I'm receiving this error with the Coalan Async library.
Error: (node:2172) UnhandledPromiseRejectionWarning: Error: Callback was already called.
Here is my code:
const updateOrCreateTrips = (trips, done) => {
const Trip = mongoose.connection.db.collection(...);
console.log(`updating or creating ${trips.length} trips`);
async.eachLimit(trips, 100, (trip, next) => {
const {...rest} = trip;
console.log(`updating trip (${id}) ${title}`);
const tripToUpdate = {//some data here...}
Trip.update(
{
_id: trip.wordpressId,
},
{
$set: tripToUpdate,
$setOnInsert: {
created: new Date(),
enabled: true,
},
},
{
upsert: true,
},
next
);
}, done);
};