In the latest version of Studio 3T, 2021.6, we’ve added support for Read Preference Tags. This addition will be of great interest for many MongoDB Atlas users who want to make full use of workload-isolated Analytics nodes or want to target queries at MongoDB nodes in specific regions.
Atlas Tagged
MongoDB Atlas is very flexible. Among other things you can create clusters with geographically or cloud distributed nodes and nodes which are isolated from the operational workload. That means a cluster could have nodes on AWS and Azure, and that some of those nodes were specifically for analytics processing and shouldn’t be used for normal workloads.
MongoDB’s connection strings already have a lot of options, but they all map to the more general cases of things. Take Read Preference which when set in a connection string sets which kind of MongoDB node the connecting application should prefer. It can be set to primary, primaryPreferred, secondary, secondaryPreferred or nearest. That starts to give you control of which of the cluster’s nodes you connect to in the cluster without targeting specific IP addresses or DNS names.
For some users though that’s not precise enough. That’s why there’s Replica Set Tags. Think of them as a set of labels that nodes in a cluster can have attached to them. Each node in a cluster is given tags as part of the replica set configuration.
When a client looks to connect to the cluster some or all of those tags can be included in the connection string’s Read Preference Tags. These make the connection go to a node which matches those tags. If that all sounds a little abstract to you, let’s look at how Atlas uses Read Preference Tags.
Atlas’s Replica Set Tags
Atlas Nodes have tags for cloud provider (provider) which say which cloud provider the node lives on. There are tags for region (region) which say which cloud provider’s region the node resides in. And there are tags for types of node (nodeType) which say what kind of work the node is configured to do. There’s also a tag for selecting nodes which take part in the normal operational workload of the cluster (workloadType).
If you set your read preference to secondary and your read preference tags to:
{ "provider":"AWS", "region":"EU-WEST-2" }
Then the connection would attempt to find a secondary in Amazon’s EU-WEST-2 region – London.
If you set a read preference tag for node type to “ANALYTICS”:
{ "nodeType":"ANALYTICS" }
MongoDB Atlas would attempt to route your connection to one of the workload isolated analytics nodes in your cluster.
And if you set your read preference tags for workload type to “OPERATIONAL”:
{ "workloadType":"OPERATIONAL" }
your connections would be evenly routed amongst all the non-analytics nodes available in the cluster.
If your read preference is PRIMARY, none of this applies as there is only one primary node. But it does apply for all other read preferences when routing your connections to secondary nodes. Read preference tags are a powerful extra lever to control how your database resources are consumed.
In Studio 3T, you can set a connection’s read preference tags in the Connection Manager. Once you have selected anything but Primary in the Read Preference option for a replica set: