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.
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.
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.
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With