Cluster Instance
The cluster instance contains 3 types of nodes: mongos, config and shard.
Both config and shard nodes use a 3-node replica set architecture. If one node fails, the system will automatically perform a high availability switchover operation, select a normal node to continue providing services, and the failed node will be checked and repaired in the background. The automatic switchover between config and shard requires no intervention from the user, the whole process is completed in less than 1 minute, and user requests can be retried in case of errors.
Each mongos runs independently, and if one node fails, it will become unavailable. Users are assigned multiple mongos nodes when they create an instance, so it is recommended that client uses the Connection URI to connect to all mongos nodes rather than a single mongos node. The client will automatically perform probing checks on the connected mongos and automatically distribute requests to normal mongos nodes.
An example connection is as follows:
mongo "mongodb://<username>:<password>@<IP1:Port1>,<IP2:Port2>/admin?authSource=admin"
Replica Set Instance
A replica set instance contains multiple mongod nodes. For example, a 3-node replica set contains 1 Primary, 1 Secondary, and 1 Hidden node. If the Primary node fails, the system will automatically select another normal Secondary node as the new Primary node, and the failed node will be checked and restored in the background.
The entire switchover and recovery process does not require user intervention, during which time connections may flash and requests may fail for up to 1 minute, and the user can retry requests that report errors.
It is recommended that when the client uses the Connection URI to connect to the document database, connect to all normal nodes and specify the replicaSet parameter. Avoid affecting the application's normal requests in the event of a single node failure.
An example connection is as follows:
mongo "mongodb://<username>:<password>@<IP1:Port1>,<IP2:Port2>/admin?authSource=admin&replicaSet=<setname>"
Single-Node Instance
A single-node instance has only one mongod node for read and write access. If one node fails, the system will check and restore the node. But the instance is unavailable during the failure.
Single-node instances are mainly used to reduce usage costs for users while ensuring data reliability. Suitable for non-core business scenarios such as testing and teaching. It is recommended to use cluster instance or replica set instance in production environment to ensure high availability of services.