1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

mongoコマンドでError: couldn't connect to server 127.0.0.1が出た時の話

Last updated at Posted at 2021-02-09

#はじめに
Node.jsの環境構築でMongoDBを接続しようとしていた時に起こったエラーの解決方法の忘備録です。
Macでの開発です。

#エラー内容

% mongo
MongoDB shell version v4.4.3
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1

#解決方法
まず参考記事のようにbrew search <パッケージ名(フォーミュラ名)>を入力してみる。

brew search mongodb 

###結果

==> Formulae
mongodb/brew/libmongocrypt               mongodb/brew/mongodb-community@3.6
mongodb/brew/mongocli                    mongodb/brew/mongodb-community@4.0
mongodb/brew/mongodb-community ✔         mongodb/brew/mongodb-community@4.2 ✔
mongodb/brew/mongodb-community-shell     mongodb/brew/mongodb-database-tools ✔
mongodb/brew/mongodb-community@3.2       mongodb/brew/mongosh
mongodb/brew/mongodb-community@3.4
==> Casks
gcollazo-mongodb
mongodb-compass
mongodb-compass-isolated-edition
mongodb-compass-readonly
mongodb-realm-studio
mongodbpreferencepane
nosqlbooster-for-mongodb
homebrew/cask-versions/mongodb-compass-beta

ターミナル上で直前にインストールしたパッケージが__太字__(上記のコード上では__チェックマーク__がついてます)になっていた。
→ここでこのパッケージ群がちゃんとインストールされていない可能性に気づく

そして着目すべきは↓

homebrew/cask-versions/mongodb-compass-beta

どうやらhomebrew/cask-versionsのパッケージ情報を更新すれば良いみたいなので下記のコマンドを入力する。

brew tap homebrew/cask-versions

###結果

Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> Updated Formulae
Updated 12 formulae.
==> New Casks
parsify
==> Updated Casks
Updated 4 casks.

==> Tapping homebrew/cask-versions
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask-versions'...
remote: Enumerating objects: 34, done.
remote: Counting objects: 100% (34/34), done.
remote: Compressing objects: 100% (28/28), done.
remote: Total 231898 (delta 16), reused 9 (delta 6), pack-reused 231864
Receiving objects: 100% (231898/231898), 59.59 MiB | 2.07 MiB/s, done.
Resolving deltas: 100% (159718/159718), done.
Tapped 175 casks (210 files, 66MB).

この後mongoコマンドを入力するとMongoDBが立ち上がり、エラー解決。

#参考
brew installでError: No available formulaが返るとき

1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?