Connect to MongoDB

This page outlines how to use MongoDB Compass to connect to a MongoDB host. 本页概述如何使用MongoDB Compass连接到MongoDB主机。You can connect to a standalone, replica set, or sharded cluster host.您可以连接到独立、副本集或分片群集主机。

Note
MongoDB Atlas

If you need to create a MongoDB host, consider using MongoDB Atlas. 如果需要创建MangGDB主机,请考虑使用MangoDB AtlasAtlas is a cloud-hosted database-as-a-service which requires no installation, offers a free tier to get started, and provides a copyable URI to easily connect Compass to your deployment.Atlas是一个云托管的数据库即服务,它不需要安装,提供了一个免费的开始层,并提供了一个可复制的URI来轻松地将Compass连接到您的部署。

If you need to install Compass, see Download and Install Compass for instructions.如果需要安装Compass,请参阅下载和安装Compass以获取说明。

  • When connecting Compass to a replica set, it is not recommended to connect directly to an individual replica set member. 将Compass连接到副本集时,不建议直接连接到单个副本集成员。If the member to which you are connected switches from a primary member to a secondary or vice versa as the result of an election, Compass may either forcibly close the connection or display stale data.如果您所连接的成员在选择后从主要成员切换到次要成员,或从次要成员切换到主要成员,则Compass可能会强制关闭连接或显示陈旧数据。

    Instead, to connect to a replica set, use either the replica set SRV record or Replica Set Name when filling in your connection information.相反,要连接到副本集,请在填写连接信息时使用副本集SRV记录副本集名称

  • Starting in MongoDB Compass 1.19, Compass displays a warning message when connected to non-genuine MongoDB instances as these instances may behave differently from the official MongoDB instances; e.g. missing or incomplete features, different feature behaviors, etc.从MongoDB Compass 1.19开始,Compass在连接到非正版MongoDB实例时会显示警告消息,因为这些实例的行为可能与官方MongoDB实例不同;e、 g.缺少或不完整的特征、不同的特征行为等。

When you open Compass, an initial connection dialog appears:打开Compass时,将显示一个初始连接对话框:

Connection dialog for pasting your connection string

Compass provides two methods to connect to your deployment, either providing your deployment connection string or filling in your deployment information in specific fields.Compass提供了两种连接到部署的方法,可以提供部署连接字符串,也可以在特定字段中填写部署信息。

Note

MongoDB Compass securely stores sensitive information entered in the connection form using an API that is specific to your operating system.MongoDB Compass使用特定于您的操作系统的API安全地存储在连接表单中输入的敏感信息。

For more information on how Compass handles sensitive data, refer to the FAQ page.有关Compass如何处理敏感数据的更多信息,请参阅常见问题页面

1
2
Disconnect menu item

Disconnecting from a MongoDB instance closes the Compass connection to the active instance and returns the Compass view to the initial connection dialog.断开与MongoDB实例的连接将关闭与活动实例的Compass连接,并将Compass视图返回到初始连接对话框。