Docs Home / Compass / Troubleshooting故障排除

Compass Connection ErrorsCompass连接错误

The sections on this page list common errors seen when connecting to MongoDB Compass and provide possible solutions.此页面上的部分列出了连接到MongoDB Compass时常见的错误,并提供了可能的解决方案。

MongoDB Not Running on the Provided Host and PortMongoDB未在提供的主机和端口上运行

Your connection failed when Compass attempted to connect to your database on the specified host and port.Compass尝试连接到指定主机和端口上的数据库时,连接失败。

Likely Causes可能原因

This error often occurs when:此错误通常发生在以下情况:

  • You provide no hostname or an invalid hostname to the Compass connect dialog.您未向Compass连接对话框提供主机名或主机名无效。
  • The destination server rejects a connection on an incorrect port.目标服务器拒绝了错误端口上的连接。
  • Your MongoDB cluster or server has been shutdown or the server hostname has changed.MongoDB集群或服务器已关闭,或者服务器主机名已更改。
  • You have a firewall actively blocking connections to/from your local network.防火墙正在主动阻止与本地网络的连接。

Solutions解决方案

The solution to this issue may depend on how your MongoDB environment is configured. Select the appropriate tab for your MongoDB environment to view possible solutions:此问题的解决方案可能取决于MongoDB环境的配置方式。为MongoDB环境选择适当的选项卡以查看可能的解决方案:

Self-Hosted Environment

Try these solutions if you have a self-hosted MongoDB server, replica set, or cluster.如果您有自托管的MongoDB服务器、副本集或集群,请尝试这些解决方案。

Ensure Your MongoDB Instance is Running确保MongoDB实例正在运行

Compass must connect to a running MongoDB instance. Make sure you have installed MongoDB and have a running mongod process. Compass必须连接到正在运行的MongoDB实例。确保你已经安装了MongoDB,并且有一个正在运行的mongod进程。You should also check that the port where your MongoDB instance is running matches the port you provide in the Compass connect dialog.您还应该检查运行MongoDB实例的端口是否与您在Compass连接对话框中提供的端口匹配。

Required Config File Setting: bindIp必需的配置文件设置:bindIp

If you recently installed the MongoDB database server and are unable to establish an initial connection to that server, verify that you have specified a valid net.bindIp setting in your server configuration file.如果您最近安装了MongoDB数据库服务器,但无法建立与该服务器的初始连接,请验证您是否在服务器配置文件中指定了有效的net.bindIp设置。

Hostname and Port主机名和端口

If your self-hosted server is listening on an external network via net.bindIp, verify that you have specified your Hostname and Port correctly in the Compass connect dialog.如果自托管服务器正在通过net.bindIp侦听外部网络,请验证您是否在Compass连接对话框中正确指定了主机名端口

MongoDB Server Moved or ShutdownMongoDB服务器已移动或关闭

It is possible that your MongoDB cluster or server has been shutdown or had its hostname has changed. Contact your database administrator for updates on the status of your database.MongoDB集群或服务器可能已关闭或主机名已更改。有关数据库状态的更新,请与数据库管理员联系。

Firewall防火墙

If you believe your firewall may be actively blocking connections to the port(s) your database(s) are operating on, try connecting from a different location, such as a home or internet cafe network. 如果您认为防火墙可能正在主动阻止与数据库正在运行的端口的连接,请尝试从其他位置连接,例如家庭或网吧网络。You can also visit http://portquiz.net/ to test your connection to different ports.您还可以访问http://portquiz.net/测试您与不同端口的连接。

Atlas Cluster

If you are connecting to an Atlas cluster, first follow the procedure described in the Connect via Compass page in the Atlas documentation. The steps on that page will help ensure that your connection settings are optimized for Atlas.如果您要连接到Atlas集群,请首先按照Atlas文档中“通过Compass连接”页面中描述的程序进行操作。该页面上的步骤将有助于确保连接设置针对Atlas进行优化。

MongoDB Server Moved or ShutdownMongoDB服务器已移动或关闭

It is possible that your MongoDB cluster or server has been shutdown or had its hostname has changed. Contact your database administrator for updates on the status of your database.MongoDB集群或服务器可能已关闭或主机名已更改。有关数据库状态的更新,请与数据库管理员联系。

Firewall防火墙

If you believe your firewall may be actively blocking connections to your database, try connecting from a different location, such as a home or internet cafe network.如果您认为防火墙可能正在主动阻止与数据库的连接,请尝试从其他位置连接,例如家庭或网吧网络。

Atlas clusters operate on port 27017. You must be able to access this port to access your cluster. To check if your local network blocks connections to port 27017, visit http://portquiz.net:27017/.Atlas集群在27017端口上运行。您必须能够访问此端口才能访问群集。要检查本地网络是否阻止连接到端口27017,请访问http://portquiz.net:27017/

Atlas IP Access List Does Not Include Your AddressAtlas IP访问列表不包括地址

Atlas only allows connections to a cluster from addresses listed in the project IP access list. Ensure that you have access listed your IP address so you can connect to your cluster.Atlas只允许从项目IP访问列表中列出的地址连接到集群。确保IP地址已列出访问权限,以便您可以连接到群集。

You can use the intelligent assistant to assist in debugging your connection errors in MongoDB Compass.您可以使用智能助手来协助调试MongoDB Compass中的连接错误。

Insert Document Button Disabled and Cannot Modify Documents插入文档按钮已禁用,无法修改文档

When using Compass, you may be in a state where you cannot perform any write operations, and can only read data.使用Compass时,您可能处于无法执行任何写入操作,只能读取数据的状态。

Possible Observations可能的观察结果

When you are in this state:当你处于这种状态时:

  • The Create Collection and Insert Document buttons are disabled.“创建集合”和“插入文档”按钮已禁用。
  • You cannot modify any of your documents.您无法修改任何文档。

Likely Cause可能原因

There are two likely causes for this behavior:这种行为可能有两个原因:

  • You are connected to a secondary member of your cluster, which does not support write operations.您已连接到群集的辅助成员,该成员不支持写操作。
  • You are using Compass Readonly edition, which does not support write operations.您使用的是Compass只读版,它不支持写操作。

Solutions解决方案

Check Read Preference Setting检查读取首选项设置

In the Compass connection dialog, set your Read Preference to Primary. This will ensure that you connect to your cluster's primary member, which supports write operations.在Compass连接对话框中,将“读取首选项”设置为“Primary”。这将确保您连接到支持写操作的集群的Primary成员。

Check Replica Set Name检查副本集名称

Check that your Replica Set Name is accurate. Compass is only able to identify the primary correctly if the replica set name is accurate.检查副本集名称是否准确。Compass只有在副本集名称准确的情况下才能正确识别主副本。

If your cluster is hosted in Atlas, you can obtain the correct replica set name using the following procedure:如果集群托管在Atlas中,则可以使用以下过程获取正确的副本集名称:

  1. Navigate to your Atlas Clusters view.导航到Atlas “Clusters”视图。
  2. Click Connect for your desired cluster.单击所需群集的“连接”。
  3. Click Connect with MongoDB Compass.点击“连接MongoDB Compass”。
  4. Copy the provided connection string.复制提供的连接字符串。
  5. Open MongoDB Compass.打开MongoDBCompass。
  6. Click Yes to auto-fill the connection settings.单击“是”自动填充连接设置。

Check Your Compass Edition检查Compass版本

You cannot perform write operations in Compass Readonly edition. You can check your Compass edition by opening the top-level Compass dropdown menu and selecting About MongoDB Compass.您无法在Compass只读版中执行写入操作。您可以通过打开顶级Compass下拉菜单并选择About MongoDB Compass来检查Compass版本。

To perform write operations, you must download a different edition of MongoDB Compass. For more information on the differences between Compass editions, see Capabilities of Compass Editions.要执行写入操作,您必须下载不同版本的MongoDB Compass。有关Compass版本之间差异的更多信息,请参阅Compass版本的功能

Connection to Cluster Shard Closed与群集分片的连接已关闭

This error means that the connection to your MongoDB cluster was closed before the initial setup completed.此错误意味着在初始设置完成之前,与MongoDB集群的连接已关闭。

Possible Observations可能的观察结果

You may see an error in MongoDB Compass similar to the following:您可能会在MongoDB Compass中看到类似以下内容的错误:

connection 3 to cluster0-shard-00-00-a1b2c.mongodb.net:27017 closed

Likely Cause可能原因

The most common source of this error is a missing Atlas IP access list entry for the public IP address where Compass is running.此错误最常见的来源是运行Compass的公共IP地址缺少Atlas IP访问列表条目。

Solution解决方案

Ensure the public IP address where Compass is running is included in your Atlas project's IP access list.确保运行Compass的公共IP地址包含在Atlas项目的IP访问列表中。

To configure your Atlas access list:要配置Atlas访问列表:

  1. Use the Context dropdown in the top-left of Atlas to select your desired Atlas project.使用Atlas左上角的上下文下拉菜单选择所需的Atlas项目。
  2. Click the Security tab.单击“安全”选项卡。
  3. Click the IP Access List menu option.单击IP访问列表菜单选项。
  4. If your IP address is not in the access list, click Add IP Address.如果IP地址不在访问列表中,请单击“添加IP地址”。
  5. Click Add Current IP Address.单击添加当前IP地址。
  6. Click Confirm.单击“确认”。

Atlas recognizes which entries in the access list include your current IP address, and appends these addresses with (includes your current IP address).Atlas会识别访问列表中的哪些条目包含您当前的IP地址,并在这些地址后附加(包括当前IP地址)。

Tip

For more information on configuring access list entries, see Configure Access List Entries in the Atlas documentation.有关配置访问列表条目的更多信息,请参阅Atlas文档中的配置访问列表条目

Not Primary or Secondary is Not Writable非主要或次要不可书写

This error message indicates that you have connected to one of the secondary members of a replica set without providing the correct replica set name and requiring a connection to a primary in your Read Preference.此错误消息表示您已连接到副本集的次要成员之一,但未提供正确的副本集名称,也不需要在读取首选项中连接到主要成员。

Solutions解决方案

Verify Atlas Replica Set Name验证Atlas副本集名称

You should ensure that you are providing the correct replica set name in the Compass connect dialog.您应该确保在Compass连接对话框中提供正确的副本集名称。

If your cluster is hosted in Atlas, you can obtain the correct replica set name using the following procedure:如果集群托管在Atlas中,则可以使用以下过程获取正确的副本集名称:

  1. Navigate to your Atlas Clusters view.导航到Atlas “Clusters”视图。
  2. Click Connect for your desired cluster.单击所需群集的“连接”。
  3. Click Connect with MongoDB Compass.单击连接MongoDB Compass。
  4. Copy the provided connection string.复制提供的连接字符串。
  5. Open MongoDB Compass.打开MongoDBCompass。
  6. Click Yes to auto-fill the connection settings.单击“是”自动填充连接设置。

Allow Compass to Connect to the Secondary允许Compass连接到辅助设备

Another approach to resolving this error is to allow Compass to connect to a secondary cluster member. Change your Read Preference to either Primary Preferred or Secondary Preferred in your connection settings. This should allow you to bypass this error and connect.解决此错误的另一种方法是允许Compass连接到辅助集群成员。在连接设置中将“阅读首选项”更改为“主要首选”或“次要首选”。这应该允许您绕过此错误并连接。

Note

When you connect to a secondary cluster member, you cannot create or modify documents, indexes, or databases. Only use this solution when you do not need to perform any write operations.连接到辅助群集成员时,无法创建或修改文档、索引或数据库。仅当您不需要执行任何写入操作时才使用此解决方案。

Tip

For more information on read preferences, see Read Preference in the MongoDB manual.有关读取首选项的更多信息,请参阅MongoDB手册中的读取首选项

Authentication Failed认证失败

When you attempt to connect to your cluster using Compass, you may encounter an error message stating Authentication Failed.当您尝试使用Compass连接到集群时,可能会遇到一条错误消息,指出“身份验证失败”。

Likely Causes可能原因

This error message is often the result of one of five conditions:此错误消息通常是以下五种情况之一的结果:

  • Your Password is missing after autofilling your connection details from a copied connection string. Compass requires you to manually enter your password in the connection dialog as a security precaution.从复制的连接字符串中自动填充连接详细信息后,密码丢失。作为安全预防措施,Compass要求您在连接对话框中手动输入密码。
  • Your Username and/or Password are incorrect.用户名和/或密码不正确。
  • You have not configured any MongoDB users for your Atlas cluster.您尚未为Atlas集群配置任何MongoDB用户
  • You did not select the correct Authentication method.您没有选择正确的身份验证方法。
  • You did not specify the correct Authentication Database. This setting corresponds to the authSource connection string option.您没有指定正确的身份验证数据库。此设置对应于authSource连接字符串选项。

    Note

    For Atlas clusters, the Authentication Database is usually admin.对于Atlas集群,身份验证数据库通常是admin

Solutions解决方案

  • Ensure you provided the correct Username and Password.确保您提供了正确的用户名和密码。
  • Ensure that the MongoDB user you are authenticating as exists.确保您正在验证的MongoDB用户存在。
  • Verify your Authentication Database and authentication mechanism.验证身份验证数据库和身份验证机制。
  • Verify that your selected authentication mechanism is supported by your MongoDB database.验证MongoDB数据库是否支持您选择的身份验证机制。

Check the Compass Logs检查Compass日志

The Compass logs can provide additional information on connection errors. You may find more detailed error messages to help diagnose your issue. For more information, see Retrieve Compass Logs.Compass日志可以提供有关连接错误的其他信息。您可能会发现更详细的错误消息,以帮助诊断问题。有关更多信息,请参阅检索Compass日志

Additional Resources其他资源