How to connect AWS Lambda in python with MonboDB cluster, here is the sample code:
import pymongo
import json
from urllib.parse import quote_plus
username = quote_plus('user')
password = quote_plus('pwd')
cluster = 'ai-beta.60op4nu.mongodb.net'
authSource = 'database'
authMechanism = 'SCRAM-SHA-256'
uri = 'mongodb+srv://' + username + ':' + password + '@' + cluster + '/?authSource=' + authSource + '&authMechanism=' + authMechanism
print(uri)
try:
client = pymongo.MongoClient(uri)
result = client['truvideo']['dealers'].find()
for x in result:
print(x)
except Exception as e:
print("An error occurred:", e)
But always i got en error like this:
An error occurred: ac-7itqhz7-shard-00-00.60op4nu.mongodb.net:27017: connection closed,ac-7itqhz7-shard-00-02.60op4nu.mongodb.net:27017: connection closed,ac-7itqhz7-shard-00-01.60op4nu.mongodb.net:27017: connection closed, Timeout: 30s, Topology Description: <TopologyDescription id: 64ca404b198e0bba955fe143, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('ac-7itqhz7-shard-00-00.60op4nu.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-7itqhz7-shard-00-00.60op4nu.mongodb.net:27017: connection closed')>, <ServerDescription ('ac-7itqhz7-shard-00-01.60op4nu.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-7itqhz7-shard-00-01.60op4nu.mongodb.net:27017: connection closed')>, <ServerDescription ('ac-7itqhz7-shard-00-02.60op4nu.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-7itqhz7-shard-00-02.60op4nu.mongodb.net:27017: connection closed')>]>
Great thanks do you know if there is a tutorial with the step by step and follow