You can start a Compass session from the command line.您可以从命令行启动Compass会话。
In enterprise environments, a scripted start can make it easier to deploy Compass. For example, to limit access to sensitive systems, you can configure a command line start so that Compass can run on a jump host.在企业环境中,脚本启动可以更容易地部署Compass。例如,为了限制对敏感系统的访问,您可以配置命令行启动,以便Compass可以在跳转主机上运行。
There are two ways to start Compass from the command line:有两种方法可以从命令行启动Compass:
Specify a connection string on the command line在命令行上指定连接字符串Specify connection details in a file在文件中指定连接详细信息
If your connection string contains sensitive information, consider using a configuration file to avoid exposing that information on the command line.如果您的连接字符串包含敏感信息,请考虑使用配置文件以避免在命令行上暴露这些信息。
Compass Executable LocationCompass可执行位置
The name and location of the Compass executable varies by operating system.Compass可执行文件的名称和位置因操作系统而异。
| Location | ||
|---|---|---|
| Linux | mongodb-compass | The installer installs it in the /usr/bin directory. |
| Windows | MongoDBCompass.exe | |
| MacOS | MongoDB Compass |
|
Command Line Connection Specification命令行连接规范
The command line invocation for Compass has two components, the path to the Compass executable and a connection string. You can optionally provide the username and password on the command line or the configuration file. The format is:Compass的命令行调用有两个组件,Compass可执行文件的路径和连接字符串。您可以选择在命令行或配置文件上提供用户名和密码。格式为:
<path/to/compass/executable>
<connection string>
--username <username> --password <password>
Note
If the username and password arguments are not provided, Compass uses the credentials in the connection string.如果未提供用户名和密码参数,Compass将使用连接字符串中的凭据。
Basic Connection String基本连接字符串
The following example uses a basic connection string for a MongoDB University training cluster. Modify the connection details to connect to your MongoDB installation:以下示例使用MongoDB大学训练集群的基本连接字符串。修改连接详细信息以连接到您的MongoDB安装:
mongodb-compass mongodb+srv://cluster0.xxxxxx.mongodb.net/libraryUsername and Password Parameters用户名和密码参数
This example uses the 此示例使用用户名和密码参数对Compass进行身份验证,以验证连接字符串中提供的MongoDB部署:username and password parameters to authenticate Compass to the MongoDB deployment provided in the connection string:
mongodb-compass mongodb+srv://cluster0.xxxxxx.mongodb.net/library
--username user1 --password password1Configuration File Connection Specification配置文件连接规范
The command line invocation for Compass can specify a configuration file.Compass的命令行调用可以指定配置文件。
The format is:格式为:
<path/to/compass/executable> \
--file=<filename> \
[--passphrase=<passphrase>] \
[<connection id>]
The components of the command invocation are:命令调用的组件包括:
The path to the Compass executableCompass可执行文件的路径A connection configuration file连接配置文件An optional passphrase for the connection configuration file连接配置文件的可选密码An optional connection id可选连接id
To create the connection configuration file, follow the steps to export the connection details from your Compass instance. The export process creates a file that includes all of your favorite connections.要创建连接配置文件,请按照以下步骤从Compass实例导出连接详细信息。导出过程会创建一个文件,其中包含您最喜欢的所有连接。
Important
If you export your saved connections without using a passphrase, the configuration file contains the plaintext version of your username and password. Use a passphrase to encrypt the password.如果在不使用密码的情况下导出保存的连接,配置文件将包含您的用户名和密码的明文版本。使用密码短语加密密码。
To open Compass and connect to your MongoDB instance, use a command line like:要打开Compass并连接到MongoDB实例,请使用以下命令行:
mongodb-compass --file=learningConnectionFile \
--passphrase=superSecret
If you have multiple favorites, include the connection id from the configuration file to specify which connection to use:如果您有多个收藏夹,请在配置文件中包含连接id,以指定要使用的连接:
mongodb-compass --file=multipleConnectionFile \
--passphrase=superSecret \
27ba0eda-c27e-46f5-a74a-2c041b1b58c4