LoginSignup
2
1

More than 5 years have passed since last update.

MongoDB Atlasに接続する

Posted at

MongoDBのDBaaS(Database as a Service)であるMongoDB AtlasにCLI(PowerShell)およびGUIビューアのMongoDB Compassで接続する方法。
筆者の環境はwindows8.1。

手順

MongoDB Atlasの登録やClusterの作成等は既に終わっているものとする。
Clusters->OverviewにあるCONNECTボタンを押す。

次の画面が表示される

  • 一番上Mongo Shellはコマンドプロンプト等CLIを使う
  • 真ん中はmongoDBのドライバ(ライブラリ)を使って自作アプリケーションから接続する方法
  • 一番下はビューアであるMongoDB Compassから接続する方法

CLIで接続する

2019/3/8現在、CLIを選んだときとCompassを選んだときに、(最新のツールを選んでいれば)、表示されるコマンドが同一なので、compassの画面で説明する。

CLIに入力するコマンドが表示されるので、Copyボタンを押す。
大体次のようなコマンドになっているはず。

PowerShell
mongo "mongodb+srv://something-something.mongodb.net/something"     --username example

実行するとパスワード入力を求められ、接続できる。

MongoDB shell version v4.0.6
Enter password:
connecting to: mongodb://something-shard-00-00-something.mongodb.net.:27017, ...

Compassで接続する

Compassを立ち上げて新規の接続を設定する。

  • 注意するのが、Hostnameで、コマンドに記載されているホスト名+ドメイン名(一つ上の画像で青いブロック:something-something.mongodb.net)を書いても接続できない。 CLIで接続したときに表示される接続先(ここではsomething-shard-00-00-something.mongodb.net)で接続できた。
  • 既に別の端末が接続している場合はRead PreferenceSecondary等に変更する

後は画像の丸を付けた個所(Authentication(Username, Password), SSL)を設定してCONNECTボタンを押す。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1