Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of cursor id error in mongodb?

I have tried the following command in pymongo:

records= db.collection_name.find({"gender":"female"}).batch_size(5)

but after a few iterations is gives:

pymongo.errors.CursorNotFound: Cursor not found, cursor id: 61593385827.

Also if I try timeout=False in the same command i.e

records= db.collection_name.find({"gender":"female"},timeout=False).batch_size(5) 

its gives

TypeError: __init__() got an unexpected keyword argument 'timeout' error.
like image 916
Mrunmayee Avatar asked Sep 23 '15 04:09

Mrunmayee


People also ask

How do I get MongoDB cursor?

In MongoDB, the find() method return the cursor, now to access the document we need to iterate the cursor. In the mongo shell, if the cursor is not assigned to a var keyword then the mongo shell automatically iterates the cursor up to 20 documents. MongoDB also allows you to iterate cursor manually.

How do I know if my MongoDB cursor is empty?

Check if the Cursor object is empty or not? Approach 1: The cursor returned is an iterable, thus we can convert it into a list. If the length of the list is zero (i.e. List is empty), this implies the cursor is empty as well.

What is MongoDB cursor timeout?

Mongo Cursors Test. A cursor is a pointer to the result set of a query. Clients can iterate through a cursor to retrieve results. By default, cursors timeout after 10 minutes of inactivity.

What is open cursor in MongoDB?

The Cursor is a MongoDB Collection of the document which is returned upon the find method execution. By default, it is automatically executed as a loop. However, we can explicitly get specific index document from being returned cursor. It is just like a pointer which is pointing upon a specific index value.


1 Answers

Try setting no_cursor_timeout=True in the query, like so:

records= db.collection_name.find({"gender":"female"}, no_cursor_timeout=True).batch_size(5)

like image 106
Andrew Avatar answered Oct 12 '22 14:10

Andrew