Start Compass from the Command Line从命令行启动Compass
On this page本页内容
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可执行文件的名称和位置因操作系统而异。
Linux | mongodb-compass | /usr/bin directory./usr/bin 目录中。 |
Windows | MongoDBCompass.exe | |
MacOS | MongoDB Compass | /Applications/MongoDB\ Compass.app/Contents/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. Compass的命令行调用有两个组件,Compass可执行文件的路径和连接字符串。You can optionally provide the username and password on the command line or the configuration file. The format is:您可以选择在命令行或配置文件中提供用户名和密码。格式为:
<path/to/compass/executable>
<connection string>
--username <username> --password <password>
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以下示例使用MongoDB大学 training cluster.
培训集群的基本连接字符串。
Modify the connection details to connect to your MongoDB installation:修改连接详细信息以连接到您的MongoDB安装:
mongodb-compass mongodb+srv://cluster0.xxxxxx.mongodb.net/library
Username and Password Parameters用户名和密码参数
This example uses the 此示例使用username
and password
parameters to authenticate Compass to the MongoDB deployment provided in the connection string:username
和password
参数对Compass进行身份验证,以验证连接字符串中提供的MongoDB部署:
mongodb-compass mongodb+srv://cluster0.xxxxxx.mongodb.net/library
--username user1 --password password1
Configuration 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. 要创建连接配置文件,请按照步骤从Compass实例导出连接详细信息。The export process creates a file that includes all of your favorite connections.导出过程会创建一个文件,其中包括您喜爱的所有连接。
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