• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

How to fix MongoDB Error Code – 95 – NotSecondary

January 2, 2024

How to Fix MongoDB Error Code – 95 – NotSecondary

MongoDB is a popular open-source NoSQL database that offers high performance, scalability, and flexibility. However, like any software, it can encounter errors that may disrupt its normal operation. One such error is MongoDB Error Code – 95 – NotSecondary. In this article, we will explore the causes of this error and provide solutions to fix it.

Understanding MongoDB Error Code – 95 – NotSecondary

MongoDB Error Code – 95 – NotSecondary occurs when a read operation is attempted on a secondary node in a replica set. In MongoDB, a replica set is a group of MongoDB instances that maintain the same data set, providing redundancy and high availability. The primary node handles all write operations, while secondary nodes replicate the data and handle read operations.

When a read operation is sent to a secondary node, it should return the requested data. However, if the secondary node is not available or not in a state to serve read operations, MongoDB throws the Error Code – 95 – NotSecondary.

Possible Causes of MongoDB Error Code – 95 – NotSecondary

There are several reasons why you might encounter this error:

  1. Node State: The secondary node may be in a state where it cannot serve read operations. This can happen during initial sync, when the node is catching up with the primary node.
  2. Network Issues: Connectivity issues between the primary and secondary nodes can prevent the secondary node from serving read operations.
  3. Node Configuration: Incorrect configuration settings on the secondary node can cause it to reject read operations.

Fixing MongoDB Error Code – 95 – NotSecondary

To resolve MongoDB Error Code – 95 – NotSecondary, you can follow these steps:

1. Check Node State

Ensure that the secondary node has completed the initial sync and is in a state to serve read operations. You can check the replication status by connecting to the primary node and running the following command:

rs.status()

If the secondary node is still catching up, you may need to wait until it completes the initial sync before attempting read operations.

2. Verify Network Connectivity

Check the network connectivity between the primary and secondary nodes. Ensure that there are no firewall rules or network configurations blocking the communication between the nodes. You can use tools like ping or telnet to test the connectivity.

3. Review Node Configuration

Verify the configuration settings on the secondary node. Ensure that the readPreference setting is correctly configured to allow read operations on the secondary node. You can check the configuration by connecting to the secondary node and running the following command:

rs.conf()

If the readPreference setting is not set correctly, you can update it using the following command:

rs.secondaryOk()

This command allows the secondary node to serve read operations.

Summary

MongoDB Error Code – 95 – NotSecondary occurs when a read operation is attempted on a secondary node that is not available or not in a state to serve read operations. To fix this error, you should check the node state, verify network connectivity, and review node configuration. By following these steps, you can ensure that your MongoDB replica set functions smoothly and provides high availability for your applications.

For more information about VPS hosting and MongoDB, visit Server.HK.

Recent Posts

  • CentOS Server Performance Tuning: Optimization Techniques for 2026
  • How to Configure SELinux in CentOS Without Breaking Your System (CentOS Stream 9/10 – 2026)
  • Managing Users and Permissions in CentOS Stream: Best Practices (CentOS Stream 9/10 – 2026)
  • How to Set Up Nginx on CentOS Stream for High-Performance Web Hosting
  • CentOS Stream Explained: Key Differences from CentOS Linux

Recent Comments

No comments to show.

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot