Sebastian Nowak
Sebastian Nowak

Reputation: 5717

Mongoose Model.aggregate stream

Standard way of streaming appears to not work under Mongoose 4.4.2:

var stream = someModel.aggregate([]).batchSize(100).stream()

It throws both on batchSize and stream, saying they are undefined.

However the following seems to work:

var stream = someModel.aggregate([]).cursor({ batchSize: 100 }).exec();

It appears to behave in a similar way. Is this the right way to stream results from .aggregate()?

Upvotes: 4

Views: 5087

Answers (2)

Tun Cham Roeun
Tun Cham Roeun

Reputation: 164

Try this for express to response as json TimeTable.aggregate([]).cursor().exec().pipe(JSONStream.stringify()).pipe(res)

Upvotes: 0

Amulya Kashyap
Amulya Kashyap

Reputation: 2373

No dear, you cannot directly create a bulk/batch you have to get some wrapper/transporter like cursor (as you already mentioned it). And it's the right way you're doing var stream = someModel.aggregate([]).cursor({ batchSize: 100 }).exec();

Thanks & Cheers

Upvotes: 11

Related Questions