When inserting an array of objects, resolve the promise only after all the data are inserted