'Connect mongodb from pymongo inside a docker container
I am running an application where each of its component running inside separate containers.Now I have mongodb running locally,it's not part of a container.How can I connect the mongodb from inside of a container.Below is the approach I tried
@app.get('/api/file', response_model=Employee)
async def readFIle():
client = pymongo.MongoClient("mongodb://127.0.0.1:27017")
mydb = client["test"]
employees = mydb.employees
employee = employees.find({"name" : "Istiaq Hossain"})
print(employee)
return employee
It's giving following error
pymongo.errors.ServerSelectionTimeoutError: 127.0.0.1:27017: [Errno 111] Connection refused,
Timeout: 30s, Topology Description: <TopologyDescription id: 627939239bf86a15e3ebfd03,
topology_type: Unknown, servers: [<ServerDescription ('127.0.0.1', 27017)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
