[WinError 10054] An existing connection was forcibly closed by the remote host

I’m getting the Connection forcibly closed error when executing the following script to do bulk_write

python movie_last_updated_migration.py
23539 documents to migrate
sandbox-shard-00-01-xxxx.mongodb.net:27017: [WinError 10054] An existing connection was forcibly closed by the remote host

Please let me know if I’m missing any configuration setting which is causing this connection to close

Please check all the connection parameters like host, database name in the file. If not resolved let me know, we can debug it by looking at the code.

Kanika

Thank you @kanikasingla. I have the following code in movie_last_updated_migration.py file

# ensure you update your host information below!
#host = "mongodb://localhost:27017"
host = "mongodb+srv://m220student:m220password@sandbox-axxxk.mongodb.net/test"


# don't update this information
MFLIX_DB_NAME = "sample_mflix"
mflix = MongoClient(host)[MFLIX_DB_NAME]

after executing the file , I am getting the following message, so I’m sure that connecting to Atlas is ok.
23539 documents to migrate

It is failing at buk_write command. I put one print statement just before that to verify, and it is printing the message.

len1=bulk_updates.__len__()
print("before bulk result",len1)

# here's where the bulk operation is sent to MongoDB
bulk_results = mflix.movies.bulk_write(bulk_updates)
print(f"{bulk_results.modified_count} documents updated")


(venv) D:\MongoDB\m220\mflix-python\migrations>python movie_last_updated_migration.py
23539 documents to migrate
before bulk result 23539
sandbox-shard-00-01-axxxxk.mongodb.net:27017: [WinError 10054] An existing connection was forcibly closed by the remote host

Hi @desabhaktula,

Thanks for sharing this information. Can you please share the code which you might have updated for update query?

Kanika