I am trying to create a node.js program that accepts a file via http POST and writes it to mongodb. To keep memory usage down I'm using req.on('data') to receive the data in chunks.
The problem is that no matter how I approach the problem I can't get round the fact that the data events get fired before mongo has written the document.
This is what I've tried to do:
However, before mongo returns in step 1, data events start being fired.
Is there a correct way to do this? I'd rather not have to resort to writing to file.
Thanks, Kev.
You can always pause the request and unpause it once Mongo completes the store.