There are many cursor issues but many a closed and old and none really fits the problem.
I have the following code
var cursor = model.Model.aggregate(pipeline).allowDiskUse(true).cursor({ batchSize: 10 }).exec();
When I than do this (like the documentation says):
cursor.each(function(){});
I get "undefined is not a function".
When I handle the cursor like a stream:
cursor.on('data', function(doc) {
console.log(doc);
});
cursor.on('error', function(error) {
console.error(error);
});
cursor.on('close', function() {
console.log('done');
});
Nothing happens.
When I do the stuff suggested in on of the tickets:
var cursor = model.Model.aggregate(pipeline).allowDiskUse(true).cursor({ batchSize: 10 }).exec().stream();
I get also "undefined is not a function"
So how can I use the cursor functionality or is it a bug?
Thanks for the help
The cursor API for aggregate is unfortunately a bit inconsistent. When you call .cursor().exec()
, you get back a raw mongodb driver cursor rather than a query stream. See docs for example of how to use, note the lack of a .stream()
call.