Replicate Set Questions

  1. Within a replica set the primary node can read and write data and the secondaries can only read data from a client application. How can you set up which member to read data from (primary and secondary)?

  2. Let’s say a replica set has 3 nodes and on another node, there is the client application using python. How can the client application query data to the replicate set? So essentially, the client app is not a replica set member but needs to query data from it. How can this be achievable?

  3. How can you access DBs and the contents of multiple nodes from a single node? I know mongosh is one way, are there other options for this? Can the DBs and contents still be accessible if the node is not a member of the replicate set, let’s say when the member has an error and is disconnected from the replicate set? Can the disconnected member still be accessible remotely?

You would set the readPreference to either secondary or secodaryPreferred

The application uses the MongoDB URI to connect to the MongoDB instance. The application does not have to be on the same machine, and in general it shouldn’t be so the app and database do not compete for the same resources (CPU, RAM, etc).

The client app has nothing to do with the replicaset. It is just an interface to get the data. Your app would make the necessary calls to the database to get the data needed.

Can the DBs and contents still be accessible if the node is not a member of the replicate set, let’s say when the member has an error and is disconnected from the replicate set? Can the disconnected member still be accessible remotely?

You can connect to the disconnected node directly by using the machine’s name/IP address instead of the replica set connecting. However it this machine cannot communicate with the other members of the replica set, it might have old or missing data. Only members that can connect to a majority of the replica set members will be kept in sync with the primary. Once the disconnected member can communicate with the rest of the replica set it will start replicating the operations again to get back into sync, as long as the oplog has not rolled over older data that this node needs.

It might be worth reading up on replication to better understand how it works.

3 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.