I looked through the documentation of mongoosejs odm and found following:
http://mongoosejs.com/docs/querystream.html
What are they used for? What can I do with them.
I am not sure if they are used for streaming docs or for dynamicly updating queries…
Regards
Well, it’s all about the API.
QueryStreamallows to to useReadStream‘s API so in order to appreciateQueryStream, you need to know more aboutReadStream/WriteStream.There are many pros:
The idea is that it gives you a unified API for read and write operations.
To answer your question “What can I do with them”:
You could do anything with or without node.js’s stream API but it definitely makes it clearer and easier to use when there’s some sort of standard.
Also, node.js’s streams are event-based (based on EventEmitter) so it helps with decoupling.
Edit:
That was more about the aspect of streams. In Mongoose’s case, a single chunk contains a document.
To clarify the advantage of the API:
node.js’s
http.ServerResponseis a writable-stream, which means you should be able to streamMongoose‘s resultset to the browser using a single line:The point is that it doesn’t matter if you’re writing to
http.ServerResponse, a file or anything else. As long as it implements a writable stream, it should work without changes.Hope I made it clearer.