Mongoose: Unable to set cursor timeout on Mongoose Schema.find().stream()

Created on 8 Sep 2015  Â·  10Comments  Â·  Source: Automattic/mongoose

{ [MongoError: cursor killed or timed out] name: 'MongoError', message: 'cursor killed or timed out' }

I am using the following code to poll the google docs API. I am polling with around 6k requests so the stream needs to be open for more than 10 minutes (default). I've tried with all the suggested online methods in vain.

Here is the code and please guide me on how to achieve this simple feat.

                // create a mongoose stream
                let orderstream = Order.find().stream();
                // start listening to events on the stream
                orderstream.on('data', (doc) => {
                    // check if data already exists

                    // add some data
                    addRow(orderstream, sheet1, doc, 0);

                }).on('error', (err) => {
                    console.log(err);
                    // send success
                    // res.json({
                    //     'status': 'failure'
                    // });
                }).on('close', () => {
                    // the stream is closed
                });

Don't give me the option to use nodejs-native mongodb driver. It works... But I don't wanna include another additional module to achieve what might be possible to be done using mongoose.

help

Most helpful comment

Timeout is false by default, so to disable timeout you need to set { timeout: true }. Weird API, I know.

All 10 comments

You should be able to specify it in the third arg to Model.find().

// 'timeout: true' gets translated by the mongodb driver into a `noCursorTimeout` http://mongodb.github.io/node-mongodb-native/2.0/api/Cursor.html#addCursorFlag
Order.find({}, {}, { timeout: true }).stream();

If that doesn't work, it might be a bug.

Does not work. Already 😫
On 9 Sep 2015 4:20 am, "Valeri Karpov" [email protected] wrote:

You should be able to specify it in the third arg to Model.find()
http://mongoosejs.com/docs/api.html#model_Model.find.

// 'timeout: true' gets translated by the mongodb driver into a noCursorTimeout http://mongodb.github.io/node-mongodb-native/2.0/api/Cursor.html#addCursorFlag
Order.find({}, {}, { timeout: true }).stream();

If that doesn't work, it might be a bug.

—
Reply to this email directly or view it on GitHub
https://github.com/Automattic/mongoose/issues/3354#issuecomment-138655847
.

Are you using a tailable cursor? It seems odd that it would take 10 minutes to stream 6k docs...

Issue is stale, re-open if still an issue.

@vkarpov15 I couldn't find any logic in mongo driver that will convert timeout to noCursorTimeout, it seems to be the other way around.

https://github.com/mongodb/node-mongodb-native/blob/2.0/lib/cursor.js#L129

Also this line really confuses me, where it's setting timeout to be false when noCursorTimeout flag is false.

So if i use a { timeout: true } as third argument to find i am supposed to DISABLE timeout ? What's the default value ?

Thank you

Timeout is false by default, so to disable timeout you need to set { timeout: true }. Weird API, I know.

@vkarpov15 I know it is an old thread, I can't set timeout :true I think it is removed on new versions. I keep getting MongoError: cursor id 5081197549009806915 not found.

@zuzu-dev as far as I can see, the option is still documented and supported: http://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#find . Can you please open a new issue and follow the issue template?

Was this page helpful?
0 / 5 - 0 ratings