Skip to content

MongoDB how to setup uri if I run mongodb via Docker? #14576

Answered by dosubot bot
mraguth asked this question in Q&A
Discussion options

You must be logged in to vote

To set up the URI for your local Docker MongoDB instance, you need to modify the MONGODB_URI environment variable to point to your local Docker MongoDB instance instead of a cloud setup.

Assuming your local Docker MongoDB instance is running on the default port 27017, your MONGODB_URI would look something like this:

export MONGODB_URI="mongodb://localhost:27017"

You can then use this URI in your Python code to connect to your local MongoDB instance:

from pymongo.mongo_client import MongoClient

uri = "mongodb://localhost:27017"
client = MongoClient(uri)  # Create a new client and connect to the server
try:
    client.admin.command("ping")  # Send a ping to confirm a successful connection

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mraguth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant