DEV Community

sm-a
sm-a

Posted on

How can I use mongoose first with mongoose find, then with forEach loop and as last with mongoose create.

When I use forEach in mongoose I get a "Cannot set headers after they are sent to the client". I am aware that the forEach is not completely executed because a res.send has apparently already taken place. Otherwise it would at least not come to this error message.

How can I use mongoose with forEach so that the code only continues when the for forEach loop is complete?

Here my code:

Top comments (0)