MongoDB cloud example with Python

I am trying to pass data back and forth via Python to a free MongoDB collection that I have created with my account. I’ve populated the cluster with the sample data. I am trying to access the documents within the shipwrecks collection. The error that I receive is:

pymongo.errors.ServerSelectionTimeoutError: cluster0-shard-00-01-5zsny.mongodb.net:27017: [WinError 10061] No connection could be made because the target machine actively refused it,cluster0-shard-00-00-5zsny.mongodb.net:27017:

Here is my code. I have removed my password on purpose. Please help.

import pymongo

cluster = pymongo.MongoClient(“mongodb+srv://markwoody:@cluster0-5zsny.mongodb.net/test?retryWrites=true&w=majority”)

db = cluster[“sample_geospatial”]
collection = db[“shipwrecks”]

results = collection.find_one()

print(results)

:wave:

Hi @Mark_Woodmansee, have you remembered to whitelist your machine’s IP address in the Atlas settings? Forgetting to do that is generally the cause of the error you’re getting.

1 Like