You can save your frequently-used connection settings as profiles. Profiles store the project IDs, organization IDs, and, optionally, API keys to use in future Atlas CLI sessions. To save time, you can specify a profile instead of using the --projectId and --orgId flags with each command. The Atlas CLI stores your profiles in a configuration file called config.toml.
注意
環境変数に保存されている設定は、プロファイルに保存されている設定よりも優先されます。 --projectIdと--orgIdフラグで指定されたプロジェクトまたは組織は、プロファイルと環境変数の両方よりも優先されます。
構成ファイルを見つけます
Atlas CLI は、オペレーティング システムに応じて次の場所に構成ファイルを保存します。
%AppData/atlascli
/Users/{username}/Library/Application Support/atlascli
$XDG_CONFIG_HOME/atlascli
デフォルトでは 、Atlas CLI は $XDG_CONFIG_HOME 環境変数で定義されたパスに構成ファイルを保存します。$XDG_CONFIG_HOME 変数で定義されているパスを希望の場所に変更できます。$XDG_CONFIG_HOME 変数の変更の詳細については、XDG ベース ディレクトリの仕様 を参照してください。
$XDG_CONFIG_HOMEが設定されていない場合、Atlas CLI は次を使用します。
$HOME/.config/atlascli
Atlas CLI は、 コマンドを実行したユーザーに、 ファイルへの読み取りアクセス権および書込みアクセス権を付与します。
プロファイルの作成
atlas auth loginまたはatlas config initコマンドを初めて実行すると、Atlas CLI はconfig.tomlファイルとデフォルトのプロファイルを自動的に作成します。 プロファイル、環境変数、または--projectId --orgIdフラグと フラグを指定せずに コマンドを実行すると、Atlas CLI はコマンドにデフォルトのプロファイルを使用します。
ユースケースを選択します
ユースケースに基づいて接続方法を選択します。
オプション | 認証方法 | ユースケース |
|---|---|---|
| Atlas のログイン認証情報と認証トークン | 非プログラムの使用に最適 |
| サービス アカウント | サービス アカウントのプログラムによる使用に最適 |
| APIキー | APIキーを使用したプログラムとしての使用に最適 |
詳細については、「接続方法の選択 」を参照してください。
前提条件を完了する
Add your host's IP address to the IP access list.
接続方法として
atlas config initを選択した場合は、 API キーを構成する必要があります。Atlas CLI のインストールがファイアウォールの内部にあり、プロキシ URL を使用したい場合は、
HTTP_PROXYまたはHTTPS_PROXYの 環境変数 を設定します。重要
Atlas CLI は、
http、https、socks5スキームをサポートしています。 プロキシ サービスのアクセス リストで、メイン ターゲット URL としてcloud.mongodb.com/を指定する必要があります。 プロキシ構成で認証が有効になっている場合は、ユーザー名とパスワードも指定する必要があります。詳細については、「プロキシサーバー」を参照してください。
実行手順
ユースケースを選択し、手順に従ってプロファイルを作成します。
非プログラムの使用
デフォルトのプロファイルまたは名前付きプロファイルを選択します。
デフォルトのプロファイルを作成します。
プロファイル、環境変数、または
--projectId--orgIdフラグと フラグを指定せずに、 コマンドを実行します。--profile defaultフラグを使用します。
--profile <profileName>フラグを使用するには、 という名前のプロファイルを作成します。
デフォルトのプロファイルを作成するには、次の手順に従います。 デフォルト プロファイルがすでに存在する場合、これらのコマンドはデフォルト プロファイルの値をアップデートします。
Specify the path to the MongoDB Shell, mongosh, on your system.
The Atlas CLI uses the specified mongosh path so that you can access your deployments. The default value is /usr/local/bin/mongosh. Press Enter to accept the default or specify the path to mongosh on your system and press Enter.
? Default MongoDB Shell Path: [? for help] (/usr/local/bin/mongosh)
プロファイル設定を確認します。
プロファイルを確認するには、構成ファイルを表示するか、 atlas config describeコマンドを実行します。 デフォルト プロファイルの場合、 <profileName>はdefaultです。
atlas config describe <profileName>
このコマンドは、次の設定を返します。 Atlas CLI は、セキュリティのためにアクセス トークンとリフレッシュ トークンの値を編集します。
SETTING VALUE "access_token": "redacted", "mongosh_path": "/usr/local/bin/mongosh", "org_id": "60c9877baf349d6fc4fd9744", "output": "json", "project_id": "60c94857241ae99848af45ad", "refresh_token": "redacted", "service": "cloud"
カスタム名のプロファイルを作成するには、次の手順に従います。
Specify the path to the MongoDB Shell, mongosh, on your system.
The Atlas CLI uses the specified mongosh path so that you can access your deployments. The default value is /usr/local/bin/mongosh. Press Enter to accept the default or specify the path to mongosh on your system and press Enter.
? Default MongoDB Shell Path: [? for help] (/usr/local/bin/mongosh)
プロファイル設定を確認します。
プロファイルを確認するには、構成ファイルを表示するか、 atlas config describeコマンドを実行します。 デフォルト プロファイルの場合、 <profileName>はdefaultです。
atlas config describe <profileName>
このコマンドは、次の設定を返します。 Atlas CLI は、セキュリティのためにアクセス トークンとリフレッシュ トークンの値を編集します。
SETTING VALUE "access_token": "redacted", "mongosh_path": "/usr/local/bin/mongosh", "org_id": "60c9877baf349d6fc4fd9744", "output": "json", "project_id": "60c94857241ae99848af45ad", "refresh_token": "redacted", "service": "cloud"
プログラムによる使用
デフォルトのプロファイルまたは名前付きプロファイルを選択します。
デフォルトのプロファイルを作成します。
プロファイル、環境変数、または
--projectId--orgIdフラグと フラグを指定せずに、 コマンドを実行します。--profile defaultフラグを使用します。
--profile <profileName>フラグを使用するには、 という名前のプロファイルを作成します。
デフォルトのプロファイルを作成するには、次の手順に従います。 デフォルト プロファイルがすでに存在する場合、これらのコマンドはデフォルト プロファイルの値をアップデートします。
Specify the path to the MongoDB Shell, mongosh, on your system.
The Atlas CLI uses the specified mongosh path so that you can access your deployments. The default value is /usr/local/bin/mongosh. Press Enter to accept the default or specify the path to mongosh on your system and press Enter.
? Default MongoDB Shell Path: [? for help] (/usr/local/bin/mongosh)
プロファイル設定を確認します。
プロファイルを確認するには、構成ファイルを表示するか、 atlas config describeコマンドを実行します。 デフォルト プロファイルの場合、 <profileName>はdefaultです。
atlas config describe <profileName>
このコマンドは、次の設定を返します。 Atlas CLI は、セキュリティのためにAPIキーの値を編集します。
SETTING VALUE "mongosh_path": "/usr/local/bin/mongosh", "org_id": "60c9877baf349d6fc4fd9744", "output": "json", "private_api_key": "redacted", "project_id": "60c94857241ae99848af45ad", "public_api_key": "redacted", "service": "cloud"
カスタム名のプロファイルを作成するには、次の手順に従います。
Specify the path to the MongoDB Shell, mongosh, on your system.
The Atlas CLI uses the specified mongosh path so that you can access your deployments. The default value is /usr/local/bin/mongosh. Press Enter to accept the default or specify the path to mongosh on your system and press Enter.
? Default MongoDB Shell Path: [? for help] (/usr/local/bin/mongosh)
プロファイル設定を確認します。
プロファイルを確認するには、構成ファイルを表示するか、 atlas config describeコマンドを実行します。 デフォルト プロファイルの場合、 <profileName>はdefaultです。
atlas config describe <profileName>
このコマンドは、次の設定を返します。 Atlas CLI は、セキュリティのためにAPIキーの値を編集します。
SETTING VALUE "mongosh_path": "/usr/local/bin/mongosh", "org_id": "60c9877baf349d6fc4fd9744", "output": "json", "private_api_key": "redacted", "project_id": "60c94857241ae99848af45ad", "public_api_key": "redacted", "service": "cloud"
プロファイルの更新
構成ファイルに保存されている設定は、次の方法でアップデートできます。
テキスト エディターを使用して
config.tomlファイルを編集します。設定には
atlas config setコマンドを実行します。 これにより、config.tomlファイル内の個々の値が編集されます。
プロファイル付きでコマンドを実行
プロファイルを使用して Atlas CLI コマンドを実行するには、次のようにします。
コマンドに
--profile <profileName>フラグを追加するか、--profile <profileName>フラグを省略してデフォルトのプロファイルを使用します。
例
このコマンドは、 myProfileという名前のプロファイルを使用します。
atlas <command> --profile myProfile
このコマンドは、デフォルトの プロファイルを使用します。
atlas <command>