mongodb aggregate not supporting DBQuery.Option.noTimeout

1,105 views
Skip to first unread message

sjmi...@gmail.com

unread,
Aug 2, 2016, 12:58:13 AM8/2/16
to mongodb-user
Hi,

When say I use
var cursor = db.collection..aggregate([ ...], {allowDiskUse: true} ).addOption(DBQuery.Option.noTimeout)
I get this error
 E QUERY    TypeError: Object #<Object> has no method 'addOption'

However when say I use
var cursor = db.collection..find({...}, {...}).addOption(DBQuery.Option.noTimeout)
It works fine.

Checking the aggregate doc
https://docs.mongodb.com/v3.0/reference/method/db.collection.aggregate/
It says:
Returns:A cursor to the documents produced by the final stage of the aggregation pipeline operation

And then checking cursor doc
https://docs.mongodb.com/v3.0/reference/method/cursor.addOption/#cursor.addOption

There is no suggestion that aggregate cursor is different from find cursor and former does not support DBQuery.Option.noTimeout.

Can anyone suggest anything as how to prevent aggregate cursor from getting timed out/reset.

Thanks
Sachin

Note mongodb version is 3.0

Kevin Adistambha

unread,
Aug 10, 2016, 4:11:03 AM8/10/16
to mongodb-user

Hi Sachin,

There is no suggestion that aggregate cursor is different from find cursor and former does not support DBQuery.Option.noTimeout.

Aggregate cursor is a different type of cursor compared to a query cursor from a find(). This is reflected in the list of supported operations of each cursor:

Can anyone suggest anything as how to prevent aggregate cursor from getting timed out/reset.

What is the use case for setting no timeout on a cursor? Generally, it is not recommended to set no timeout on a cursor, since if the application crashes while it is processing the cursor, the cursor (with no timeout) cannot be terminated by the server. This cursor will continue to take up resources on the server until the server is restarted.

Having said that, if you find that your application processing time frequently exceeds the cursor timeout for aggregation queries, you could either:

  • Fetch all results from the server and cache them in the application, thus not depending on the cursor being held in the server.
  • Use the $out aggregation operation to output the aggregation results into a temporary collection, then perform your processing using this collection.

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages