mongodbspring-bootspring-webfluxmongo-driver

Reactive Mongo secondaryPreferred


In our applications, we've configured the MongoDB readPreference to secondaryPreferred within a replica set consisting of 1 primary and 3 secondary hosts. Could someone provide clarification on how the reactive MongoDB Java driver behaves while streaming data using secondary DB hosts? Specifically, does it consistently use the same secondary DB host for streaming all data, or is there a mechanism in place to dynamically switch between different secondary hosts during the streaming process?


Solution

  • According to Read Preference Modes there is no explicit statement, but unless you specified maxStalenessSeconds and based on

    If matching secondaries are found, the client selects a random secondary from the nearest group of matching secondaries.

    I would assume it takes a random secondary node also if no tag list is provided.