Advanced Routing

  • Note: The driver's advanced routing capability is provided as part of the extensions jar. See the Notes at the bottom of this documentation for details.

Why Advanced Routing?

For information on the logic behind the advanced routing and the design for the solution see our series of blog posts.


By default the extensions will not automatically enable the use of the advanced routing in sharded environments. Users must enable the specific type of routing they want to use.

  • The '''default''' mode is provided by the core driver and has the driver connect to the closest '''mongos'''. As the default mode it requires no additional configuration.
  • The '''targeted''' mode enables the driver to look for a '''mongos''' on the same server as the driver has determined will be used by the '''mongos''' to service the request. In the cases the driver cannot determine the appropriate shard server then the driver will fall-back to using the closest '''mongos''' it can find.

To enable '''targeted''' mode simply set either the system property '''mongodb.shard.connection.mode''' or the environment variable '''MONGODB_SHARDING_MODE''' to '''targeted'''. The comparison is case-insensitive and any other value will revert the connection to the '''default''' mode.

Future versions of the driver and extensions will move the setting to the normal configuration class and also enable additional modes.


The advanced routing capability is provided via the driver's extensions jar available to license holders. Please contact Allanbank Consulting, Inc. for information on licensing the driver and obtaining the extensions jar.