I
I
IDONTSUDO2019-12-02 21:03:30
Node.js
IDONTSUDO, 2019-12-02 21:03:30

Node js asynchronous iteration of large object?

I have a task, just out of my head. I really want to know how this can be done. It is not necessary to provide code to solve it.
Let's say I have an object consisting of four million arrays.
I need to do 4 million iterations on it. And at each iteration, I need to take some data and what to do in the database.
let's say like this:

let Users = req.newsUser

for (let i = 0; Users.length > i; i++) {
Subscription.find({ userBy: Users[i].user }, (err, subscriptions) => {
return res.status(200).json(subscriptions)
}
}

How can one iterate over such an object without blocking the event loop? Not using pub/sub mechanisms

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question