There are three important differences for an application accessing data on a sharded cluster, listed as follows:
- The port is most likely not going to be the default of 27017.
- Connecting directly to one of the shard members does not return a full dataset.
- To get the best results, connect to a mongos instance configured for the sharded cluster.
To modify the port number, all you need to do is to modify the connection string argument supplied to the pymongo.mongo_client.MongoClient instance, as shown here, in a /path/to/repo/chapters/16/test_shard_one_server.py file:
hostName = 'server1.biglittle.local:27018';
client = MongoClient(hostName);
Another consideration, however, is that shards are most likely going to be configured as replica sets, requiring a further alteration of the connection string, as illustrated in the following code snippet:
hostName = 'repl_shard_1/server1.biglittle.local:27018, \
...