Since mongoose now supports promises, you can use Promise.all().then() , so it will be returned when all promises are resolved.
Promise.all([ obj1.save(), obj2.save(), obj3.save() ]) .then(console.log) .catch(console.error)
In fact, if you always call save() , you can use Array.map() here:
Promise.all([ obj1, obj2, obj3 ].map( obj => obj.save() )
Aaand also use es6 syntax to destroy the resulting array:
Promise.all([ obj1, obj2, obj3 ].map( obj => obj.save() ) .then( ([ savedObj1, savedObj2, savedObj3 ]) => {
Zilvinas
source share