Cursor iteration is very slow in pymongo

mongodb query return command cursor .to iterate the cursor and get the data its very slow takes around 90 sec for 250 records .Can someone help

using pymongo 3.9.0

Hi @Yogita_Pal,

First of all, welcome to the MongoDB Community.
Could you share your code?

All the best,

Rodrigo (a.k.a. Logwriter)

cursor= db.collection.aggregate(
    [
        {
            '$addFields':
                {

                    'yearSubstring': {'$substr': ["$__json.created_on", 0, 10]},
                }
        },
        {
            '$match': {
                '$and': [{'yearSubstring': {'$gte': '12/01/2019'}}, {'yearSubstring': {'$lte': '12/02/2019'}}]
            }
        }

    ])

#query take around 4-5 seconds
while cursor and cursor.alive:
list_element= cursor.next()
items.append(list_element)
#but this while to read each cursor data take around 100 seconds

Just call list(cursor) to create a list of the results.

1 Like

I had already done that before and tried again it also takes same takes same time .what is standard bench mark for reading 1000 records from mongodb server using pymongo 3.9 .