How does mongo choose which secondary node to return data

if read preference is secondary, and there is two or more secondary node, which node will be selected to return data? is it random?
even if i set maxStalenessSeconds, and all secondary nodes do not exceed maxStalenessSeconds, how does mongo choose ?

Hi @Yi_deng,

The process for secondary read preference is described in the Server Selection Algorithm documentation. As per the description for secondary read preference mode for replica sets:

  1. The driver assembles a list of eligible secondary members. maxStalenessSeconds and tag sets specified in the read preference can further restrict the eligibility of the members.
  2. If the list of eligible members is not empty, the driver determines which eligible member is the “closest” (i.e. the member with the lowest average network round-trip-time) and calculates a latency window by adding the average round-trip-time of this “closest” server and the localThresholdMS. The driver uses this latency window to pare down the list of eligible members to those members that fall within this window.
  3. From this list of eligible members that fall within the latency window, the driver randomly chooses an eligible member.

Regards,
Jason

1 Like

Dear, thanks a lot . it is very usefull.

1 Like

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