Docs HomeMongoDB Compass

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. 这个问题的解决方案可能取决于如何配置MongoDB环境。Select the appropriate tab for your MongoDB environment to view possible solutions:为您的MongoDB环境选择适当的选项卡以查看可能的解决方案:

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. Compass必须连接到正在运行的MongoDB实例。Make sure you have installed MongoDB and have a running mongod process. 确保您已经安装了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. 您的MongoDB集群或服务器可能已关闭或主机名已更改。Contact your database administrator for updates on the status of your database.请与数据库管理员联系以获取数据库状态的更新。

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/以测试您与不同端口的连接。

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

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

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

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. Atlas集群在27017港运行。您必须能够访问此端口才能访问群集。To check if your local network blocks connections to port 27017, visit http://portquiz.net:27017/.要检查您的本地网络是否阻止连接到端口27017,请访问http://portquiz.net:27017/.

Atlas IP Whitelist Does Not Include Your AddressAtlas IP白名单不包括您的地址

Atlas only allows connections to a cluster from addresses listed in the project IP whitelist. Atlas只允许从项目IP白名单中列出的地址连接到集群。Ensure that you have whitelisted your IP address so you can connect to your cluster.请确保您已将IP地址列入白名单,以便连接到群集。

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. 在“Compass连接”对话框中,将“读取首选项”设置为“主要”。This will ensure that you connect to your cluster's primary member, which supports write operations.这将确保您连接到集群的主要成员,该成员支持写操作。

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 “群集”视图。
  2. Click Connect for your desired cluster.单击所需集群的“连接”。
  3. Click Connect with MongoDB Compass.单击Connect with MongoDB Compass。
  4. Copy the provided connection string.复制提供的连接字符串。
  5. Open MongoDB Compass.打开MongoDB Compass。
  6. Click Yes to auto-fill the connection settings.单击“是”以自动填充连接设置。

    Image showing autofill connection dialog

Check Your Compass Edition检查您的Compass版本

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

To perform write operations, you must download a different edition of MongoDB Compass. 要执行写操作,您必须下载不同版本的MongoDB Compass。For more information on the differences between Compass editions, see Capabilities of Compass Editions.有关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 whitelist 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 whitelist.确保Compass运行的公共IP地址包含在Atlas项目的IP白名单中。

To configure your Atlas whitelist:要配置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 Whitelist menu option.单击“IP白名单”菜单选项。
  4. If your IP address is not in the whitelist, click Add IP Address.如果您的IP地址不在白名单中,请单击“添加IP地址”。
  5. Click Add Current IP Address.单击“添加当前IP地址”。
  6. Click Confirm.单击“确认”。

Atlas recognizes which entries in the whitelist include your current IP address, and appends these addresses with (includes your current IP address).Atlas识别白名单中的哪些条目包括您当前的IP地址,并将这些地址附加为(包括您的当前IP地址)。

Tip

See also: 另请参阅:

For more information on configuring whitelist entries, see Configure Whitelist 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 “群集”视图。
  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.打开MongoDB Compass。
  6. Click Yes to auto-fill the connection settings.单击“是”以自动填充连接设置。

    Image showing autofill connection dialog

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. 解决此错误的另一种方法是允许Compass连接到次要集群成员。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.这应该允许您绕过此错误并进行连接。

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

See also:

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. Compass日志可以提供有关连接错误的其他信息。You may find more detailed error messages to help diagnose your issue. 您可能会发现更详细的错误消息,以帮助诊断您的问题。For more information, see Retrieve Compass Logs.有关详细信息,请参阅检索Compass日志

Additional Resources其他资源