|
| 1 | +.. _comp-command-line-connect: |
| 2 | + |
| 3 | +=================================== |
| 4 | +Start Compass from the Command Line |
| 5 | +=================================== |
| 6 | + |
| 7 | +.. default-domain:: mongodb |
| 8 | + |
| 9 | +.. contents:: On this page |
| 10 | + :local: |
| 11 | + :backlinks: none |
| 12 | + :depth: 1 |
| 13 | + :class: singlecol |
| 14 | + |
| 15 | +.. include:: /includes/intro-command-line-connection.rst |
| 16 | + |
| 17 | +There are two ways to start |compass-short| from the command line: |
| 18 | + |
| 19 | +- :ref:`Specify a connection string on the command line |
| 20 | + <compass-connect-cmd-line>` |
| 21 | +- :ref:`Specify connection details in a file |
| 22 | + <compass-connect-file-based>` |
| 23 | + |
| 24 | +If your connection string contains sensitive information, consider |
| 25 | +using a configuration file to avoid exposing that information on |
| 26 | +the command line. |
| 27 | + |
| 28 | +.. _compass-executable-location: |
| 29 | + |
| 30 | +Compass Executable Location |
| 31 | +--------------------------- |
| 32 | + |
| 33 | +The name and location of the |compass-short| executable varies by |
| 34 | +operating system. |
| 35 | + |
| 36 | +Linux |
| 37 | +~~~~~ |
| 38 | +The executable is called ``mongodb-compass``. The installer installs it |
| 39 | +in the ``/usr/bin`` directory. |
| 40 | + |
| 41 | +Windows |
| 42 | +~~~~~~~ |
| 43 | + |
| 44 | +The executable is called ``MongoDBCompass.exe``. The installer installs |
| 45 | +it in a folder you pick during the installation process. |
| 46 | + |
| 47 | +MacOS |
| 48 | +~~~~~ |
| 49 | +The executable is called ``Compass``. The installer installs |
| 50 | +it under the Applications folder: |
| 51 | + |
| 52 | +.. code-block:: shell |
| 53 | + |
| 54 | + /Applications/MongoDB\ Compass.app/Contents/MacOS/MongoDB\ Compass |
| 55 | + |
| 56 | +.. _compass-connect-cmd-line: |
| 57 | + |
| 58 | +Command Line Connection Specification |
| 59 | +------------------------------------- |
| 60 | + |
| 61 | +The command line invocation for |compass-short| has two components, the |
| 62 | +path to the |compass-short| executable and a connection string. The |
| 63 | +format is: |
| 64 | + |
| 65 | +.. code-block:: shell |
| 66 | + :copyable: false |
| 67 | + |
| 68 | + <path/to/compass/executable> <connection string> |
| 69 | + |
| 70 | +This example is like the basic connection string for a `MongoDB |
| 71 | +University <https://learn.mongodb.com/>`__ training cluster. Modify the |
| 72 | +connection details to connect to your MongoDB installation: |
| 73 | + |
| 74 | +.. code-block:: shell |
| 75 | + :copyable: false |
| 76 | + |
| 77 | + mongodb-compass mongodb+srv://cluster0.cpxklfq.mongodb.net/library |
| 78 | + |
| 79 | + |
| 80 | +.. _compass-connect-file-based: |
| 81 | + |
| 82 | +Configuration File Connection Specification |
| 83 | +------------------------------------------- |
| 84 | + |
| 85 | +The command line invocation for |compass-short| can specify a |
| 86 | +configuration file. |
| 87 | + |
| 88 | +The format is: |
| 89 | + |
| 90 | +.. code-block:: shell |
| 91 | + |
| 92 | + <path/to/compass/executable> \ |
| 93 | + --file=<filename> \ |
| 94 | + [--passphrase=<passphrase>] \ |
| 95 | + [<connection id>] |
| 96 | + |
| 97 | +The components of the command invocation are: |
| 98 | + |
| 99 | +- The path to the |compass-short| executable |
| 100 | +- A connection configuration file |
| 101 | +- An optional passphrase for the connection configuration file |
| 102 | +- An optional connection id |
| 103 | + |
| 104 | +To create the connection configuration file, follow the steps to |
| 105 | +:ref:`export the connection details <compass-export-connections-cli>` |
| 106 | +from your Compass instance. The export process creates a file that |
| 107 | +includes all of your favorite connections. |
| 108 | + |
| 109 | +.. important:: |
| 110 | + |
| 111 | + If you export your saved connections without using a passphrase, the |
| 112 | + configuration file contains the plaintext version of your username |
| 113 | + and password. Use a passphrase to encrypt the password. |
| 114 | + |
| 115 | +To open |compass-short| and connect to your MongoDB instance, use a |
| 116 | +command line like: |
| 117 | + |
| 118 | +.. code-block:: |
| 119 | + :copyable: false |
| 120 | + |
| 121 | + mongodb-compass --file=learningConnectionFile \ |
| 122 | + --passphrase=superSecret |
| 123 | + |
| 124 | +If you have multiple favorites, include the connection id from the |
| 125 | +configuration file to specify which connection to use: |
| 126 | + |
| 127 | +.. code-block:: |
| 128 | + :copyable: false |
| 129 | + |
| 130 | + mongodb-compass --file=multipleConnectionFile \ |
| 131 | + --passphrase=superSecret \ |
| 132 | + 27ba0eda-c27e-46f5-a74a-2c041b1b58c4 |
| 133 | + |
0 commit comments