'promise all several mongodb aggregate

i would like to promise all several mongodb aggregate

AllPromises = an array with promises (if I'm not wrong)

  const AllPromises = []
  for (
    let i = 0;
    i < SIZE;
    i++
  ) {
    const promise = () => {
      try {
        return client
          .db(DATABASE)
          .collection('collectionName')
          .aggregate([...])
          .toArray()
       } catch (err) {
        console.error('Error', err)
        return []
      }
    }
    allPromises.push(promise)
  }

  const resolvedPromises = await Promise.all(allPromises).flat()

  console.log(resolvedPromises)

expected result: array of documents But I get [[Function: promise], ...]



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source