このチュートリアルでは、 Atlas 設定コマンドを使用して次の操作を行う方法を説明します。
Atlas プロジェクトに 1 つのクラスターを作成します。
サンプル データを Atlas クラスターにロードします。
IP アドレスをプロジェクトの IP アクセス リストに追加します。
Atlas クラスターの MongoDB ユーザーを作成します。
MongoDB Shell、
mongoshを使用して新しいクラスターに接続します。
新しい Atlas アカウントの作成中にこれらのすべての手順を実行するには、「 Atlas を使い始める 」を参照してください。
構成ファイルを使用してクラスターを作成するには、atlas setup ではなく --file オプションを指定して、 Atlasクラスター作成コマンドを実行します。 Atlas クラスターの構成ファイルの詳細については、「クラスター構成ファイル 」を参照してください。
また、 atlas setupを使用して Atlas アカウントを作成し、Atlas で認証することもできます。 詳細については、 「 Atlas の使用 」を参照してください。
前提条件
始める前に、次のタスクを完了してください。
Atlas 組織の作成
Atlas API のポート 443 (HTTPS) と MongoDB 接続のポート 27017 での発信アクセスを確認します。
Atlas クラスターの構成
Atlas でM0クラスターを作成するには、 atlas setupコマンドを使用します。 M0クラスターには運用上の制限がいくつかあります。
このコマンドは、次の方法で実行できます。
デフォルト設定モード: コマンドは、デフォルト設定を持つサンプル共有階層クラスターを作成します。
対話モード: コマンドはクラスター設定を要求し、デフォルト値を提供します。
非対話型モード: オプションを指定して コマンドを実行します。
[] タブをクリックすると、ご希望モードのコマンドが表示されます。
コマンドは、次のデフォルト設定を持つサンプル共有階層クラスターを作成します。
クラスター名:
Cluster<number>サービスプロバイダー:
AWSプロバイダー リージョン:
US_EAST_1クラスター階層:
M0ディスクサイズ:
0.5GBデータベースユーザー名:
Cluster<number>データベースユーザー パスワード:
abcdef12345IP アドレス からの接続を許可します。
<YourIPAddress>サンプル データのロード:
Yesshell開きます:
No
注意
パスワードは自動生成されたランダムな値です。 abcdef12345はサンプル値です。
atlas setup --forceWe are deploying Cluster9876543...
Please store your database authentication access details in a secure locationDatabase User Username: Cluster9876543Database User Password: abcdef12345
Creating your cluster... [Its safe to 'Ctrl + C']Cluster created.Your connection string: mongodb+srv://cluster9876543.example.mongodb.net
Loading sample data into your cluster... [Its safe to 'Ctrl + C']
Now you can connect to your Atlas cluster with: mongosh -u Cluster9876543 -p abcdef12345 mongodb+srv://cluster9876543.example.mongodb.netコマンドはクラスター設定を要求し、デフォルト オプションを提供します。 プロンプトが表示されたら、 Yを押し、次にEnterを押してデフォルト設定を受け入れます。
atlas setupPress [Enter] to use the default values.
Enter [?] on any option to get help.
[Default Settings]Cluster Name: Cluster9876543Cloud Provider and Region: AWS - US_EAST_1Database User Username: Cluster9876543Load sample data: YesAllow connections from (IP Address): <your-IP>? Do you want to set up your first free database in Atlas with default settings (it's free forever)? YesWe are deploying Quickstart-9876543...
Please store your database authentication access details in a secure location:Database User Username: Cluster9876543Database User Password: abcdef12345
Creating your cluster... [Its safe to 'Ctrl + C']Cluster created.
Your connection string: mongodb+srv://cluster9876543.example.mongodb.net
Loading sample data into your cluster... [Its safe to 'Ctrl + C']
Now you can connect to your Atlas cluster with: mongosh -u Cluster9876543 -p abcdef12345 mongodb+srv://cluster9876543.example.mongodb.netコマンドは、次の設定を持つサンプル共有階層クラスターを作成します。
クラスター名:
getStartedサービスプロバイダー:
AWSプロバイダー リージョン:
US_EAST-1クラスター階層:
M0ディスクサイズ:
2GBMongoDB バージョン:
5.0レプリカセット ノード
3
atlas setup --clusterName getStarted --provider AWS --region US_EAST_1 --username testUser --password changeMe --accessListIp 192.0.2.15 --skipSampleData --forceWe are deploying getStarted...
Please store your database authentication access details in a secure location:Database User Username: testUserDatabase User Password: changeMe
Creating your cluster... [Its safe to 'Ctrl + C']
Now you can connect to your |service| cluster with: mongosh -u testUser -p changeMe mongodb+srv://getStarted.example.mongodb.net配置を確認します
クラスターのプロビジョニング後、接続する前に準備が完了していることを確認します。
チェックポイント | 検証ステップ |
|---|---|
CLI がインストールされました |
|
認証済み |
|
クラスター作成 | CLI 出力には、接続文字列とともに |
IP アクセス リストの更新 | CLI 出力により、IP アドレスが追加されたことが確認されます。 |
接続に成功しました |
|
次のステップ
Atlas クラスターを作成して検証した後、次の操作を実行できます。
アプリケーションの接続:
mongoshまたは MongoDB ドライバーと接続文字列を使用します。セキュリティの構成: アクセスリストに IP アドレスを追加し、アプリケーション固有のデータベースユーザーを作成し、またはプロダクションワークロードのプライベートエンドポイントを有効にします。
データの読み込み: 設定時に
--loadSampleDataフラグを使用するか、mongoimport または mongorestore を使用して自分のデータを読み込みます。クラスター ステータスの表示: UI にログインするか、Atlas CLI で
atlas clustersコマンドを実行します。クラスターの増やしまたは変更: クラスターの変更を参照してください。