Should I close the cursor connection after it's exhausted?

Hi Everyone,

The main question in the address is, so should I take care of the connection to close immediately after it’s exhausted? I’m working on a project where the time for a connection is 10 seconds. That connection is enough for some of a few smaller queries, but after a time ( approx 10 seconds ) the connection is thrown and got connection timeout.

We’re using pymongo@3.12 and I saw in the implementation the cursor is usable as a context manager whereas in the exit branch the connection will be closed.

One query runs under 1 second so I don’t think the problem is with that, but I suspect the connection is in custody if I don’t care about closing it.

One question that is related to that is, will the performance decrease if I close every connection after a query? I run approx 150 queries synchronously one after another.

Thanks in advance,

I cannot modify the original post, but I wanted to wry I suspect something keeps up the connection among the usage of cursors, and that’s why I got connection timeout from the mongo.