Connect your SQL tool, such as Tableau, Power BI, or DBeaver to your MongoDB Atlas or Enterprise Advanced (EA) database.
All three SQL Interface deployment options use the same JDBC and ODBC drivers, so the steps on this page are the same whether you connect to an Atlas dedicated cluster, an Atlas federated database instance, or a self-managed Enterprise Advanced (EA) deployment. Configure your deployment to accept SQL connections first. To learn how, see SQL Interface Server Setup.
注意
MongoDB officially supports Tableau (Desktop, Server, or Cloud) and Power BI Desktop (Desktop and Service) with its JDBC and ODBC drivers. You can use the JDBC and ODBC drivers with other SQL-92 compatible tools, but MongoDB cannot guarantee compatibility. Test your specific SQL Interface features to confirm support.
连接Tableau
Connect an Atlas dedicated cluster, an Atlas federated database instance, or a self-hosted Enterprise Advanced (EA) database to Tableau (Desktop or Server) using the Tableau Connector for MongoDB.
先决条件
MongoDB 数据库,配置为 SQL 接口:
An Atlas dedicated cluster or a self-managed Enterprise Advanced (EA) deployment must run MongoDB 6.0 or later.
An Atlas federated database instance must be mapped to one or more data stores, and each Atlas cluster that it reads from must run MongoDB 5.0 or later. To learn more, see Deploy a Federated Database Instance.
MongoDB JDBC 驱动程序。要安装,请参阅 SQL 接口驱动程序设置。
步骤
以下步骤向您展示如何使用Tableau连接到MongoDB :
下载适用于MongoDB的Tableau连接器。
注意
Tableau Desktop 和 Tableau 服务器 2025 及更高版本捆绑了适用于 MongoDB 的 Tableau Connector。如果您的 Tableau 版本已包含该连接器,请跳过此步骤。如需使用不同于 Tableau 捆绑版本的其他版本,请完成此步骤。
对于 Tableau Desktop,您也可以从 Tableau 安装连接器。在 Tableau Exchange 中搜索 MongoDB SQL interface by MongoDB,然后点击 Install and restart Tableau。
Download the latest Tableau Connector
tacofile from the MongoDB download center.将
taco文件移至操作系统的相应目录中:Windows:
C:\Users\<user>\Documents\My Tableau Repository\ConnectorsMacOS:
~/Documents/My Tableau Repository/ConnectorsLinux:
/opt/tableau/connectors
重要
如果您下载新版本的适用于MongoDB的Tableau Connector,请从 Connectors目录中删除上一个 taco文件,以确保Tableau使用最新版本。
获取MongoDB 数据库连接信息。
选择与您的部署类型对应的标签页,获取有关如何获取连接信息的说明:
Go 到项目的 Atlas 专用集群或联合数据库实例。
单击 Connect(连接)。
选择 Atlas SQL Interface 选项。
选择 Select your driver 下拉列表下的 Tableau Connector 选项。
从下拉列表中选择 Tableau。
从 Database 下拉列表中选择要连接的数据库。
复制连接字符串和连接参数。
在后续步骤中,请使用此信息与Tableau连接。
Use a connection string that is compatible with the MongoDB Java driver. To learn more, see Connection URI.
选择身份验证方法。
从下拉列表中选择您的 Authentication Mechanism。
有关所有支持的身份验证机制的信息,请参阅SQL接口身份验证。
Username:输入您的MongoDB用户名。
Password:输入您的MongoDB密码。
使用以下方法之一配置 PEM 证书:
使用 PEM 文件路径:
在
mongodb_jdbc.properties文件中,将x509pempath属性设立为 PEM 文件的路径。示例,x509pempath=/certs/client-cert.pem。如果您的 PEM 文件是未加密的,请勿选择 Provide PEM Contents。无需采取进一步操作。
如果您的 PEM 文件已加密,请选择 Provide PEM Contents 并在 Password 字段中输入文件的密码。
提供 PEM 内容:
选中 Provide PEM Contents 旁边的复选框,然后在 Password字段中输入您的证书数据:
未加密内容:将完整的证书内容直接粘贴到字段。
加密内容:粘贴包含以下内容和密码的JSON对象:
{ "pem": "<PEM-CONTENT>", "passphrase": "<PEM-PASSPHRASE>" }
在 Username字段中输入Kerberos主体名称。示例,user@EXAMPLE.COM。
OIDC 的连接对话框中不需要其他属性或字段。
配置 Tableau 日志记录
要更改 MongoDB JDBC 驱动程序的日志配置,请将日志属性添加到 mongodb_jdbc.properties 文件中。此文件的位置取决于您的平台:
平台 | 路径 |
|---|---|
macOS |
|
Windows |
|
Tableau 服务器 (RHEL) |
将此文件复制到所有服务器节点。 |
要配置日志记录,请将以下属性添加到文件中:
loglevel=INFO logdir=<path-to-log-directory>
loglevel 属性用于设置驱动程序日志的详细程度。它接受以下值,按详细程度递增排序:OFF、SEVERE、WARNING、INFO、FINE 和 FINER。默认值为 OFF。
logdir 属性设置驱动程序写入日志文件的目录。目录必须已经存在。如果您省略 logdir 或将其设置为 console,则驱动程序会将日志写入控制台,而不是写入文件。
重要
在生产环境中,请从 SEVERE 日志级别开始。仅在必须诊断问题时才提高级别,因为每个级别都会增加大量输出。在 FINER 级别,驱动程序会记录日志,记录每个结果集中每个单元格检索数据的每次调用。
要了解有关 Tableau 属性文件的更多信息,请参阅 Tableau 文档。
连接 Power BI
Connect an Atlas dedicated cluster, an Atlas federated database instance, or a self-hosted Enterprise Advanced (EA) database to Power BI using the Power BI Connector for MongoDB.
先决条件
MongoDB 数据库,配置为 SQL 接口:
An Atlas dedicated cluster or a self-managed Enterprise Advanced (EA) deployment must run MongoDB 6.0 or later.
An Atlas federated database instance must be mapped to one or more data stores, and each Atlas cluster that it reads from must run MongoDB 5.0 or later. To learn more, see Deploy a Federated Database Instance.
MongoDB ODBC驾驶员。要进行安装,请参阅SQL接口驱动程序安装程序。要使用 Direct Query,必须安装 1.2 或更高版本。
Power BI 桌面 64 位。Microsoft 每月会更新并发布一次 Power BI,Atlas 仅支持最新版本的 Power BI Desktop。
Windows操作系统。要学习;了解Power BI Desktop 支持的Windows操作系统版本,请参阅Microsoft文档。
步骤
以下步骤向您展示如何使用 Power BI连接到MongoDB :
下载适用于MongoDB的 Power BI Connector 。
从MongoDB下载中心下载最新的 Power BI Connector
pqx文件。注意
Power BI Connector for MongoDB随 Power BI Desktop 一起提供。如果您的 Power BI Desktop 版本已有MongoDB Atlas SQL Connector,请跳过此步骤。要使用与 Power BI Desktop 捆绑版本不同的版本,请完成此步骤。
将Connector文件移至以下目录路径:
C:\Users\<user>\Documents\Power BI Desktop\Custom Connectors.如果这个文件夹不存在,请创建。
获取MongoDB 数据库连接信息。
选择与您的部署类型对应的标签页,获取有关如何获取连接信息的说明:
Go 到项目的 Atlas 专用集群或联合数据库实例。
单击 Connect 按钮。
选择 Atlas SQL Interface 选项。
选择 Select your driver 下拉列表下的 Power BI Connector 选项。
复制连接字符串。
请使用此信息在后续步骤中连接到 Power BI。
Use your MongoDB deployment URI. To learn more, see Connection Strings.
从 Power BI Desktop 连接。
打开 Power BI Desktop。
从 Home 菜单中选择 Get data。
查找并选择 MongoDB Atlas SQL 连接器。
在搜索栏中键入
mongo以查找新 connector。选择 MongoDB Atlas SQL 。
单击 Connect(连接)。
输入 URI 和数据库名称,然后单击 OK。
MongoDB URI 是您在上一个步骤中复制的连接字符串。
在 Native query 字段中,您可以选择输入 SQL 查询。Power BI 使用 SQL 查询作为数据的直接来源。连接后,您还可以在 Power Query 编辑器中添加或更改 SQL 查询。
输入您的 Atlas User name 和 Password,然后点击 Connect。
By default, users can access all namespaces that their roles and connection URI permit. If you use custom roles to restrict access, you can grant users access to additional namespaces in the Edit User menu. To learn more, see Configure Database Users.
有关其他支持的身份验证机制的信息,请参阅SQL接口身份验证。
直接查询
Direct Query is a connection mode available with the Power BI Connector for MongoDB version 1.2 and later. To use Direct Query, you must install MongoDB ODBC Driver version 1.2 or later. You don't need to configure a DSN.
Direct Query 是标准导入模式的替代方案,允许您直接查询数据库。这 ACID 一致性保证数据是最新的,但可能需要更长的时间才能返回结果。
直接查询不支持某些操作。 如果您尝试执行不支持的动作,Power BI会提示您切换到导入模式。
连接 DBeaver
使用MongoDB JDBC驱动程序将Atlas专用集群、 Atlas联合数据库实例或自管理Enterprise Advanced (EA)部署连接到 DBeaver。
先决条件
MongoDB 数据库,配置为 SQL 接口:
An Atlas dedicated cluster or a self-managed Enterprise Advanced (EA) deployment must run MongoDB 6.0 or later.
An Atlas federated database instance must be mapped to one or more data stores, and each Atlas cluster that it reads from must run MongoDB 5.0 or later. To learn more, see Deploy a Federated Database Instance.
MongoDB JDBC 驱动程序。要安装,请参阅 SQL 接口驱动程序设置。
步骤
要从 DBeaver 连接:
获取MongoDB 数据库连接信息。
选择与您的部署类型对应的标签页,获取有关如何获取连接信息的说明:
Go 到项目的 Atlas 专用集群或联合数据库实例。
单击 Connect 按钮。
选择 Atlas SQL Interface 选项。
选择 Select your driver 下拉列表下的 JDBC Driver 选项。
从 Database 下拉列表中选择要连接的数据库。
复制连接字符串。
请使用此信息在后续步骤中连接到 DBeaver。
Use a connection string that is compatible with the MongoDB Java driver. To learn more, see Connection URI.
打开DBeaver应用程序。
创建一个数据库连接。
在 DBeaver 中,单击 Database 并从下拉菜单中选择 New Database Connection,打开 Connect to a database 模式。
从数据库列表中,选择您在上一步中创建的
MongoDB数据库驱动程序。如果没有看到
MongoDB,请在模式窗口中选择 All(全部)类别。单击 Next(连接)。
在 Main(设置)标签页中,输入以下信息:
JDBC URL
从上一步中获取的连接字符串。
用户名
已获得连接授权的MongoDB用户。
密码
与MongoDB用户关联的密码。
在 Driver properties(驱动程序属性)标签页中,展开 User Properties(用户属性)。添加以下键值属性:
database
虚拟数据库的名称。
user
用于连接的 MongoDB 用户。如果您在上一步中输入了
Username,则不是必需的。
后续步骤
将 SQL 工具连接到 MongoDB 数据库后,您就可以查询数据了。要了解详情,请参阅:
注意
要使用私有端点进行连接,请参阅使用私有端点连接到 MongoDB SQL 接口。