1

Can pymongo use to connect mongodb bi connector in python?

I had tried to connect a mongodb bi connector as the code below:

from pymongo import MongoClient

# Replace 'localhost' with the hostname or IP address of your BI 
Connector server
host = 'localhost'
port = 27017  # Default port for MongoDB

# Connect to the MongoDB BI Connector without specifying username 
and password
mongo_uri = f"mongodb://{host}:{port}/"
client = MongoClient(mongo_uri)

# Now you can use the 'client' object to interact with the 
MongoDB BI Connector
# For example, you can access databases and collections like 
this:
db = client['your_database_name']
collection = db['your_collection_name']

# Perform your operations on the collection here

The code above do work for connect to the MongoDB host but it do not work for MongoDB bi connector so I want to ask is pymongo support to connect to MongoDB bi connector? If yes, can you provide some example and documentation? Thanks for help!

1 Answers1

2

The MongoDB BI Connector presents a MySQL interface and is a bridge to a running MongoDB server. You do not connect to it using the MongoDB python driver. Instead, start the BI connector daemon:

mongosqld --mongo-uri 'mongodb://your_uri' --schema your_schema.drdl  &

This will create a MySQL-wire protocol endpoint on port 3307. Then, connect using mysqlsh or the python mysql driver, e.g.:

mysqlsh --sql user@localhost:3307
Buzz Moschetti
  • 7,057
  • 3
  • 23
  • 33