Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where to specify "noCursorTimeout" option using nodejs-mongodb driver?

it might be obvious, but right now I'm not able to either find it in the docs or google it...

I'm using mongodb with the nodejs-driver and have a potentially long operation (> 10 minutes) pertaining to a cursor which does get a timeout (as specified in http://docs.mongodb.org/manual/core/cursors/#cursor-behaviors).

In the nodejs-driver API Documentation (http://mongodb.github.io/node-mongodb-native/2.0/api/Cursor.html) a method addCursorFlag(flag, value) is mentioned to be called on a Cursor.

However, there's no example on how to do it, and simply calling e.g.

objectCollection.find().limit(objectCount).addCursorFlag('noCursorTimeout', true).toArray(function (err, objects) {
    ...
}

leads to a TypeError: Object #<Cursor> has no method 'addCursorFlag'.

So how to go about making this Cursor exist longer than those 10 minutes?

Moreover, as required by the mongodb documentation, how do I then manually close the cursor?

Thanks!

like image 435
Julian Rubisch Avatar asked Feb 02 '15 10:02

Julian Rubisch


2 Answers

The example you've provided:

db.collection.find().addCursorFlag('noCursorTimeout',true)

..works fine for me on driver version 2.14.21. I've an open cursor for 45 minutes now.

Could it be you were using 1.x NodeJS driver?

like image 187
Небојша Камбер Avatar answered Oct 23 '22 09:10

Небојша Камбер


so I've got a partial solution for my problem. it's doesn't say so in the API docs, but apparently you have to specify it in the find() options like so:

objectCollection.find({},{timeout: false}).limit(objectCount).toArray(function (err, objects) {
    ...
}

however still, what about the cleanup? do those cursors ever get killed? is a call to db.close() sufficient?

like image 4
Julian Rubisch Avatar answered Oct 23 '22 08:10

Julian Rubisch