Connection closes after the 101th document in find()

I’ve been trying to iterate over every single document in my collection, but after the 101th the progress freezes and after about 30 seconds causes a bunch of errors to be thrown about a closed connection.

Future exception was never retrieved
future: <Future finished exception=ServerSelectionTimeoutError("cluster0-shard-00-00.8oorp.mongodb.net:27017: [WinError 10054] An existing connection was forcibly closed by the remote host,cluster0-shard-00-02.8oorp.mongodb.net:27017: [WinError 10054] An existing connection was forcibly closed by the remote host,cluster0-shard-00-01.8oorp.mongodb.net:27017: [WinError 10054] An existing connection was forcibly closed by the remote host, Timeout: 30s, Topology Description: <TopologyDescription id: 61ec2aa967debdfa1d0aa5e2, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('cluster0-shard-00-00.8oorp.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('cluster0-shard-00-00.8oorp.mongodb.net:27017: [WinError 10054] An existing connection was forcibly closed by the remote host')>, <ServerDescription ('cluster0-shard-00-01.8oorp.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('cluster0-shard-00-01.8oorp.mongodb.net:27017: [WinError 10054] An existing connection was forcibly closed by the remote host')>, <ServerDescription ('cluster0-shard-00-02.8oorp.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('cluster0-shard-00-02.8oorp.mongodb.net:27017: [WinError 10054] An existing connection was forcibly closed by the remote host')>]>")>

I’m just using a find with no parameters:

async for document in db.data.players.find({}):

Any way to either make the find function return more than 101 documents or to increase the timeout?

I’m using motor to interact with the mongo database.

Pardon me if I’m asking in the wrong place, please let me know where I should go to ask this question.

So apparently that 101 number is the batch size.

I can change it and can get more than the 101 elements. So it might be that something happens when trying to request a second batch.

I fixed it, the threads were conflicting with one another…

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.