tencent cloud

Feedback

Troubleshooting MongoDB Connection Failures

Last updated: 2024-04-12 14:15:50

    Overview

    You can use a CVM instance to connect to the automatically assigned private network address of a TencentDB for MongoDB instance as instructed in Connecting to TencentDB for MongoDB Instance. If connection fails, troubleshoot the problem as follows:

    Troubleshooting

    No.
    Possible Cause
    Troubleshooting Method
    Solution
    1
    The CVM and TencentDB for MongoDB instance cannot be interconnected over the private network.
    The CVM and TencentDB for MongoDB instance are not in the same VPC. To interconnect over the private network, the two instances must be under the same account and in the same VPC.
    The security group is incorrectly configured.
    To use the CVM instance to access the MongoDB instance, you need to configure an outbound rule in the security group of the CVM instance. If the target of the outbound rule isn't "0.0.0.0/0" and the protocol port isn't "ALL", the IP and port of the MongoDB instance should be added to the outbound rule.
    To use the CVM instance to access the MongoDB instance, you need to configure an inbound rule in the security group of the MongoDB instance. If the source of the inbound rule isn't "0.0.0.0/0" and the protocol port isn't "ALL", the IP and port of the CVM instance should be added to the inbound rule.
    1. Log in to the CVM console and view the CVM network information in Instance Configuration in the instance list.
    2. Log in to the TencentDB for MongoDB console and view the MongoDB network information in the instance list. For more information, see Viewing Instance Details.
    3. Check whether the CVM and TencentDB for MongoDB instances are in the same network.
    4. Log in to the CVM instance and run telnet 10.x.x.34 27017. Check whether the TencentDB for MongoDB Network port can be accessed normally.
    The failed connection linkage is as shown below:
    
    The successful connection linkage is as shown below:
    
    
    The following conditions may cause a connection failure due to network issues.
    The CVM instance is in a VPC, but the TencentDB for MongoDB instance is in the classic network. We recommend that you switch the network type of the MongoDB instance to VPC. For more information, see Switching Instance Network.
    The CVM instance is in the classic network, but the TencentDB for MongoDB instance is in a VPC. We recommend that you switch the network type of the CVM instance from classic network to VPC. For more information, see Switching to VPC.
    The CVM and TencentDB for MongoDB instances are in different VPCs in the same region. We recommend that you migrate the MongoDB instance to the VPC of the CVM instance. For more information, see Switching Instance Network.
    The CVM and TencentDB for MongoDB instances are in different VPCs in different regions. We recommend that you create a CCN instance between the two VPCs.
    The CVM and TencentDB for MongoDB instances are in different VPCs under different accounts. We recommend that you create a CCN instance between the two VPCs.
    The security group of the CVM instance is incorrectly configured.
    1. Go to the Security Group page in the CVM console, find the security group bound to the CVM instance in the security group list, and click its name to enter its details page.
    2. On the Outbound rule tab, click Add Rule.
    Type: Select Custom.
    Target: Enter the IP or IP range of your MongoDB instance.
    Protocol Port: Enter the private network port of the MongoDB instance.
    Policy: Select Allow.
    The security group of the MongoDB instance is incorrectly configured.
    1. Log in to the Security Group console, find the security group bound to the MongoDB instance in the security group list, and click its name to enter its details page.
    2. On the Inbound rule tab, click Add Rule. Enter the allowed IP address/range and port, then select Allow.
    Type: Select Custom.
    Source: Enter the IP or IP range of your CVM instance.
    Protocol Port: Enter the private network port of the MongoDB instance.
    Policy: Select Allow.
    2
    The username or password is incorrect.
    When you try to log in and access a database instance, the CVM instance displays an error message like Error: Authentication failed, indicating that the account name or password is incorrect.
    Log in to the TencentDB for MongoDB console, go to the Instance Details page, select the Database Management tab to enter the Account Management page, and view the information of all accounts of the current database or reset passwords. For detailed directions, see Account Management.
    3
    Database access password contains symbols such as % and @.
    The driver or client such as MongoShell cannot automatically escape % and @ in the password, causing conflicts between these symbols and connection string address. This results in incorrect username or password. The error message may show as 'Password cannot properly be URL decoded' or 'Error: Authentication failed`.
    Special characters in the access password should be handled according to the following escape rules: Exclamation mark "!": escaped as %21 at "@": escaped as %40 Warning Sign "#": escaped as %23 Percent sign "%": escaped as %25 Caret "^": escaped as %5e Asterisk "*": escaped as %2a Left parenthesis "(": escaped as %28 Right parenthesis ")": escaped as %29 Underscore "_": escaped as %5f For example, if the original password is ^%@132121a, then the password after escape should be: ^%25%40132121a.
    4
    The mongo shell version is too old.
    Log in to the CVM instance and run mongo --version to view the version information.
    To ensure successful authentication, install mongo shell 3.0 or later. For detailed directions, see Install MongoDB.
    5
    The authentication database is not correctly used in the connection string of the client.
    For users created in the console: TencentDB for MongoDB uses the admin database as the authentication database during login authentication, so the port in a URI must be followed by /admin to specify it. After authentication, you can switch to a specific business database for reads/writes.
    For users created on the command line: Directly specify the corresponding authentication database. For example, for users created under the test database, specify test as the authentication database.
    For users created in the console: Check whether the connection string configured in the client program contains /admin or authSource=admin.
    For users created on the command line: Check whether the authentication database in the connection string has the correct database name.
    Log in to the TencentDB for MongoDB console. In the Network Configuration section on the Instance Details page, directly copy the URI connection string of the default account. For other accounts, change it to the correct authentication database and try connecting again. For more information, see Connecting to TencentDB for MongoDB Instance.
    If the problem persists, submit a ticket for assistance.
    6
    There are operations that block other requests. For example, if an index creation operation is performed in the foreground during peak hours (with the background option being false), the operation will block all other operations and cause requests to be locked until the index is created in the foreground. For options to create an index, see Index Builds on Populated Collections.
    Check the index creation method.
    Create indexes in the background. However, it takes more time to create indexes in this way. For specific options for index creation, see db.collection.createIndex(). You can also run the currentOp command to check the progress of index creation. The specific command is as follows:
    db.currentOp( { $or: [ { op: "command", "query.createIndexes": { $exists: true } }, { op: "insert", ns: /\\.system\\.indexes\\b/ } ] } )
    7
    Check whether the number of connections to the client has reached the upper limit. Each instance has a limit on the number of connections, and if it is exceeded, new connections cannot be made.
    Log in to the TencentDB for MongoDB console, go to the Database Management page, select the Manage Connection tab, and view the instance's Max Connections, Real-time connections, and Connection Utilization. For more information, see Connection Management.
    To troubleshoot high connection utilization, see Troubleshooting High Connection Utilization.
    Note:
    The authentication database for users created in the console is the admin database, so the users need to specify admin as the authentication database during login. The users created with the command line, such as those created under the test database, need to specify test as the authentication database.
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support