Let's say that you've developed a fantastic application. The original code, however, was designed to work with a single server running MongoDB. Now, the company has implemented a replica set. The first question on your mind might be:Â Will my existing code work on a replica set? Let's have a look.
Here is a simple test program that connects to a single server and returns the result from a simple query:
import pprint
from pymongo import MongoClient
hostName = 'member1.biglittle.local';
client = MongoClient(hostName);
result = client.biglittle.users.find_one({}, {"businessName":1,"address":1})
pprint.pprint(result)
The source code can be found at /path/to/repo/chapters/14/test_replica_set_connect_using_one_server.py.
From this screenshot, you can see that even though the member1 mongod instance is part of a replica set, the return results are the same, just as if member1 had been a standalone mongod instance:
However...