0

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!

0

1 Answer 1

2

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 an ip or address to connect to a remote database)
  • Dabase name
Sign up to request clarification or add additional context in comments.

2 Comments

not mongodb+srv://?
@mousetail not necessary if your are not working with Atlas

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.