フロントエンドデベロッパーのメモ

スキル: HTML/Jade/Jinja2, CSS/SCSS, JavaScript(ES6), Angular, React,Next, Redux, Node, Express, Python, Flask, Postgres, Redis, MongoDB, Kafka, Knex, SQLAlchemy, React Native, EXPO, GraphQL/Apollo, REST, AWS, Heroku, Docker, CircleCI, SCRUM, XP, Vim, TDD

dbuserとdbpasswordってどこにあるの?Where is my dbuser and dbpassword in MongoDB?

English is below.

MongoDBをExpress.jsで作ったAPIサーバー上で使用する際に、データベースを確立した時のMongoDB URLがデータベースにリクエストを送る時に必要になります。この時にdbuserとdbpasswordが必要になるのですが、これは一体どこからくるのか?という話です。 最初はmLabに登録した際のユーザーネームとパスワードかと思いましたが、もしそうだとするとデータベース確立するたびに同じユーザーネームとパスワードを使用することになりセキュリティ上から見ても危険すぎます。

実はdbuserとdbpasswordに関しての説明は、mLabのサイトにも記載されています。なので、一応mLabのリンクも貼っておきます。 https://docs.mlab.com/connecting/

しかしここでは、簡単にどこで情報を入手するかをご紹介します。 データベースを確立すると、mLabサイトのHOME画面にあなたのデータベースのリストがあるはずです。そのリストの中で今回使用したいデータベース名をクリックすると詳細ページにアクセスしますが、私の場合は下図のようなタブリストがあります。 https://docs.mlab.com/connecting/ このリストの中の「Users」を開くと、右手側に「Add Database user」と記載されたボタンがあります。ここをクリックすることで、お好きなdbuserとdbpasswordを設定することが可能です。

After you deployed your database in MongoDB, you can see MongoDB URI. But where is your dbuser and dbpassword? Do they mean your user and password on mLab? No no. You need to define by yourself. I referred this page by the way.

https://docs.mlab.com/connecting/

After your deployment of your database and go HOME, you can see your deployments. Click your deployment. Click Users tab at the collection of tabs: Collections, Users, Stats, Backups, Tools. f:id:morita657:20180806164730p:plain

Now you can pass your dbuser and dbpassword on your URI.