Gebruik Promise.all
binnen save
functie, dan kunt u deze gebruiken zoals u verwacht
function save(){
var promises = [
new Promise(function(resolve, reject) {
Collection1.collection.insert(collections1, function(err, done){
if(err)
reject(err);
else
resolve(done);
});
}),
new Promise(function(resolve, reject) {
Collection2.collection.insert(collections2, function(err, done){
if(err)
reject(err);
else
resolve(done);
});
}),
new Promise(function(resolve, reject) {
Collection3.collection.insert(collections3, function(err, done){
if(err)
reject(err);
else
resolve(done);
});
})
];
return Promise.all(promises);
}
save().then(function(){
console.log('success');
}).catch(function(){
console.log('error');
})