Performance issue - pymongo - fetching all entries in index - over 1 mill names?

Hi all, so using pymongo and filter to just select just names (which I have in a single unique index) also excluded _id.

When looping over the returned names and adding them to a set it seems to struggle and take a long time to complete the operation. However, if I pull the details from a text file with the same information I can complete the same operation very quickly.

Is there a better way to fetch data one has in an index other than using find please?