I meant to use Promises like this:
`async function RunReport(report) {
c.db.collection(“activity”).aggregate(report).then( (cursor) => {
do somthing…
});
}
in this case, the app isn’t blocking the code while fetching the data…
anyway I see that toArray() is a pretty heavy operation by itself:
toArray()
there are other async solutions for that like:
MongoDB forum discussion
or running on the cursor one-by-one and accumulate your result batch as you want:
Cursor one-by-one fetch