Mongoose: aggregate cursor how to

Created on 1 Sep 2015  路  1Comment  路  Source: Automattic/mongoose

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

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Igorpollo picture Igorpollo  路  3Comments

ArThoX picture ArThoX  路  3Comments

simonxca picture simonxca  路  3Comments

tarun1793 picture tarun1793  路  3Comments

gustavomanolo picture gustavomanolo  路  3Comments