Hi,
From the name of your script it looks like you might be running on Azure? If so, you may have to reduce your keepalive setting to avoid networking timeouts.
If you're not on Azure, can you provide some details on your specific O/S, MongoDB deployment (standalone, replica set, or sharded cluster?) and hosting (AWS, bare metal, etc).
Regards,
Stephen