Nyaaaaaaaa
Nyaaaaaaaa

Reputation: 21

How to connect to MongoDB with using python

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!

Upvotes: 0

Views: 1931

Answers (1)

BSP
BSP

Reputation: 775

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

Upvotes: 2

Related Questions