punkave / mongo-dump-stream

Pipe entire mongodb databases through the shell, or to a node stream. It's what you wanted mongodump to be.
MIT License
51 stars 11 forks source link

setImmediate instead of callback on stream write #6

Closed qlayer closed 9 years ago

qlayer commented 9 years ago

I was using the code for some export and import and stumbled on an error 'Premature end of stream' while importing a previously exported file. The reason was that my exported file did not had endDatabase at the end. It was caused because the last write did not finish and callback was returned before that, because of setImmediate. I worked around that by adding a last empty write on the stream with a callback, which solved the issue. My question is there a reason for using setImmediate instead of the stream.write's callback ?

boutell commented 9 years ago

Good suggestion. This change has been published as 0.3.3.

Note that we still don't close the underlying stream, so you should do that.