How to Connect to a Shard Set
Introduction
The sharded cluster mode enables data distribution across multiple machines, allowing MongoDB to scale horizontally through sharding. Horizontal scaling involves partitioning the system’s dataset and load across multiple servers and adding additional servers as needed to increase capacity. Expanding deployment capacity can be achieved by adding extra servers, which may offer a more cost-effective solution than relying on high-end single-machine hardware. MongoDB’s sharded clusters support very large datasets and high-throughput operations, providing features like large data volume handling, high scalability, high performance, a flexible data model, and high availability.
Format
In general clients, they can use the MongoDB URL mode to connect to the shard set. The standard URI connection protocol is as follows:
mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[database][?options]]
Connection Example
Assuming there is such a shard set on the console:
The access address in the list is the connection address of all mongos nodes. Replacing ’****’ with the cluster password to make the connection:
mongodb://root:****@10.60.153.61:27017,10.60.252.47:27017
The “read-write separation connection string is as follows”:
mongodb://root:thisispassword@10.60.153.61:27017,10.60.252.47:27017/admin?readPreference=secondary