Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb cursor id not valid error

Tags:

python

mongodb

I am trying to iterate through this loop:

for doc in coll.find() 

I get the following error at the 100,000th plus record.

File "build\bdist.win32\egg\pymongo\cursor.py", line 703, in next File "build\bdist.win32\egg\pymongo\cursor.py", line 679, in _refresh File "build\bdist.win32\egg\pymongo\cursor.py", line 628, in __send_message File "build\bdist.win32\egg\pymongo\helpers.py", line 95, in _unpack_response pymongo.errors.OperationFailure: cursor id '1236484850793' not valid at server 

what does this error mean?

like image 289
codious Avatar asked Apr 24 '12 12:04

codious


People also ask

How do I know if my MongoDB cursor is empty?

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 cursor object in MongoDB?

In MongoDB, when the find() method is used to find the documents present in the given collection, then this method returned a pointer which will points to the documents of the collection, now this pointer is known as cursor.

What is cursor in Python MongoDB?

find() to search documents in collections then as a result it returns a pointer. That pointer is known as a cursor. Consider if we have 2 documents in our collection, then the cursor object will point to the first document and then iterate through all documents which are present in our collection.


1 Answers

Maybe your cursor timed out on the server. To see if this is the problem, try to set timeout=False`:

for doc in coll.find(timeout=False) 

See http://api.mongodb.org/python/1.6/api/pymongo/collection.html#pymongo.collection.Collection.find

If it was a timeout problem one possible solution is to set the batch_size (s. other answers).

like image 87
Reto Aebersold Avatar answered Sep 29 '22 10:09

Reto Aebersold