|
| 1 | +.. _compass-force-connection-options: |
| 2 | +.. _specify-read-preference-tags: |
| 3 | + |
| 4 | +================================ |
| 5 | +Specify Read Preference and Tags |
| 6 | +================================ |
| 7 | + |
| 8 | +.. default-domain:: mongodb |
| 9 | + |
| 10 | +.. contents:: On this page |
| 11 | + :local: |
| 12 | + :backlinks: none |
| 13 | + :depth: 2 |
| 14 | + :class: singlecol |
| 15 | + |
| 16 | +You can use the ``forceConnectionOptions`` option to set required connection |
| 17 | +option values on |compass-short|. By setting required connection options such as |
| 18 | +read preference, you can restrict how users connect to your MongoDB deployment |
| 19 | +and ensure that their read operations don't impact the availability of replica |
| 20 | +set primaries. |
| 21 | + |
| 22 | +Procedure |
| 23 | +--------- |
| 24 | + |
| 25 | +In this example, you limit read operations to read only from ``SECONDARY`` |
| 26 | +replica set members with the ``ANALYTICS`` and ``READ_ONLY`` tags. You can |
| 27 | +specify these options on the command line or in a :ref:`configuration |
| 28 | +file <config-file>`. |
| 29 | + |
| 30 | +Command Line Example |
| 31 | +~~~~~~~~~~~~~~~~~~~~ |
| 32 | + |
| 33 | +The following command starts |compass| from the command line and uses |
| 34 | +``--forceConnectionOptions`` to set the ``readPreference`` and |
| 35 | +``readPreferenceTags`` options: |
| 36 | + |
| 37 | +.. code-block:: sh |
| 38 | + |
| 39 | + <path-to-Compass-executable> \ |
| 40 | + --forceConnectionOptions.readPreference=secondary \ |
| 41 | + --forceConnectionOptions.readPreferenceTags=nodeType:ANALYTICS \ |
| 42 | + --forceConnectionOptions.readPreferenceTags=nodeType:READ_ONLY |
| 43 | + |
| 44 | +.. note:: |
| 45 | + |
| 46 | + The name and filepath of the |compass-short| executable depend on your |
| 47 | + operating system. |
| 48 | + |
| 49 | +Configuration File Example |
| 50 | +~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 51 | + |
| 52 | +You can specify the |compass-short| configuration file in either EJSON |
| 53 | +or YAML format. To set the ``readPreference`` and ``readPreferenceTags``, use |
| 54 | +``--forceConnectionOptions``: |
| 55 | + |
| 56 | +EJSON |
| 57 | +````` |
| 58 | + |
| 59 | +.. code-block:: json |
| 60 | + |
| 61 | + { |
| 62 | + "forceConnectionOptions": [ |
| 63 | + ["readPreference", "secondary"], |
| 64 | + ["readPreferenceTags", "nodeType:ANALYTICS"], |
| 65 | + ["readPreferenceTags", "nodeType:READ_ONLY"] |
| 66 | + ] |
| 67 | + } |
| 68 | + |
| 69 | +YAML |
| 70 | +```` |
| 71 | + |
| 72 | +.. code-block:: yaml |
| 73 | + |
| 74 | + forceConnectionOptions: |
| 75 | + - readPreference: secondary |
| 76 | + - readPreferenceTags: nodeType:ANALYTICS |
| 77 | + - readPreferenceTags: nodeType:READ_ONLY |
| 78 | + |
| 79 | +Learn More |
| 80 | +---------- |
| 81 | + |
| 82 | +To learn more about the |compass| configuration file, see |
| 83 | +:ref:`config-file`. |
0 commit comments