I'm pretty new to mongodb and i'm tryin to figure out how can I connect to my database with python externally.
import pymongo
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["mydatabase"]
mycol = mydb["customers"]
in this example, you connect to your mongodb using a localhost, but I cant figure out how to connect my DB by remote and not locally. (More like, how do I get even a URI to put in there, im digging in mongodb website but im lost)
Thanks in advance!
CodePudding user response:
From the documentation:, connection string:
mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]
What you need at least:
- User
- Password
- Host (you are using
localhost
, you will need anip
oraddress
to connect to a remote database) - Dabase name