You can use the forceConnectionOptions option to set required connection option values on Compass. By setting required connection options such as read preference, you can restrict how users connect to your MongoDB deployment and ensure that their read operations don't impact the availability of replica set primaries.
Procedure
In this example, you limit read operations to read only from SECONDARY replica set members with the ANALYTICS and READ_ONLY tags. You can specify these options on the command line or in a configuration
file.
Command Line Example
The following command starts MongoDB Compass from the command line and uses --forceConnectionOptions to set the readPreference and readPreferenceTags options:
<path-to-Compass-executable> \ --forceConnectionOptions.readPreference=secondary \ --forceConnectionOptions.readPreferenceTags=nodeType:ANALYTICS \ --forceConnectionOptions.readPreferenceTags=nodeType:READ_ONLY
Note
The name and filepath of the Compass executable depend on your operating system.
Configuration File Example
You can specify the Compass configuration file in either EJSON or YAML format. To set the readPreference and readPreferenceTags, use --forceConnectionOptions:
EJSON
{ "forceConnectionOptions": [ ["readPreference", "secondary"], ["readPreferenceTags", "nodeType:ANALYTICS"], ["readPreferenceTags", "nodeType:READ_ONLY"] ] }
YAML
forceConnectionOptions: - readPreference: secondary - readPreferenceTags: nodeType:ANALYTICS - readPreferenceTags: nodeType:READ_ONLY
Learn More
To learn more about the MongoDB Compass configuration file, see Configuration File Settings.