Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function findInCollection(collection, repeat){
  2.   const array = Array.from(Array(repeat).keys())
  3.  
  4.   const promises = array.map(async (i) => {
  5.     return new Promise((resolve, reject) => {
  6.       collection.find({}).toArray((err, docs) => {
  7.         console.log(`query ${i} => ${docs.length}`)
  8.         err ? reject(err) : resolve(docs)
  9.       })
  10.     })
  11.   })
  12.  
  13.   Promise.all(promises).then(console.log('terminouuu'))
  14.  
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement