Pymongo可以用来在Python中连接MongoDB BI连接器吗?

huangapple go评论83阅读模式
英文:

Can pymongo use to connect mongodb bi connector in python?

问题

pymongo可以在Python中用于连接MongoDB BI Connector吗?

我尝试过使用以下代码连接MongoDB BI Connector:

from pymongo import MongoClient

# 用你的BI Connector服务器的主机名或IP地址替换'localhost'
host = 'localhost'
port = 27017  # MongoDB的默认端口

# 连接到MongoDB BI Connector,不指定用户名和密码
mongo_uri = f"mongodb://{host}:{port}/"
client = MongoClient(mongo_uri)

# 现在你可以使用'client'对象与MongoDB BI Connector交互
# 例如,你可以像这样访问数据库和集合:
db = client['your_database_name']
collection = db['your_collection_name']

# 在集合上执行你的操作

上述代码可以连接到MongoDB主机,但似乎无法连接到MongoDB BI Connector。所以我想问一下,pymongo是否支持连接到MongoDB BI Connector?如果支持,是否可以提供一些示例和文档?感谢帮助!

英文:

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

得分: 2

MongoDB BI Connector 提供了一个 MySQL 接口,它是连接到运行中的 MongoDB 服务器的桥梁。您不使用 MongoDB Python 驱动程序连接到它。相反,启动 BI 连接器守护程序:

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

这将在端口 3307 上创建一个 MySQL-wire 协议端点。然后,使用 mysqlsh 或 Python 的 MySQL 驱动程序进行连接,例如:

mysqlsh --sql user@localhost:3307
英文:

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

huangapple
  • 本文由 发表于 2023年7月31日 22:38:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76804673.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定