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.
QueryStream
allows to to use ReadStream
's API so in order to appreciate QueryStream
, you need to know more about ReadStream
/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.ServerResponse
is a writable-stream, which means you should be able to stream Mongoose
's resultset to the browser using a single line:
// 'res' is the http response from your route's callback.
Posts.find().stream().pipe(res);
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.