前提
Homebrewがインストールされている
手順
1.HomebrewからmongoDBをインストールする
Last login: Sat Apr 27 14:57:37 on ttys001
xxxxxx-no-MBP:~ xxxxxx$ brew install mongodb-community@4.0
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
ballerina ghq istioctl neovim
ccache iamy mysql swiftlint
Error: No available formula with the name "mongodb-community@4.0"
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
git -C "$(brew --repo homebrew/core)" fetch --unshallow
Error: No previously deleted formula found.
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.
mongodb-community@4.0という名前のformulaはありません。
一ヶ月以内に削除したformulaを探しています。
2.最初にtapをしなければいけないらしい
xxxxxx-no-MBP:~ xxxxxx$ brew tap mongodb/brew
==> Tapping mongodb/brew
Cloning into '/usr/local/Homebrew/Library/Taps/mongodb/homebrew-brew'...
remote: Enumerating objects: 12, done.
remote: Counting objects: 100% (12/12), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 12 (delta 3), reused 9 (delta 2), pack-reused 0
Unpacking objects: 100% (12/12), done.
Tapped 5 formulae (42 files, 56.3KB).
3.もう一度、HomebrewからmongoDBをインストールする
xxxxxx-no-MBP:~ xxxxxx$ brew install mongodb-community@4.0
==> Installing mongodb-community from mongodb/brew
==> Downloading https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-4.0.9.tgz
######################################################################## 100.0%
==> Caveats
To have launchd start mongodb/brew/mongodb-community now and restart at login:
brew services start mongodb/brew/mongodb-community
Or, if you don't want/need a background service you can just run:
mongod --config /usr/local/etc/mongod.conf
==> Summary
🍺 /usr/local/Cellar/mongodb-community/4.0.9: 20 files, 221.0MB, built in 18 seconds
4.MongoDBをサービスとして起動させる
サービスとして動作させる方法と別の方法もあるようです。
xxxxxx-no-MBP:~ xxxxxx$ brew services start mongodb-community@4.0
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 17, done.
remote: Counting objects: 100% (17/17), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 17 (delta 0), reused 12 (delta 0), pack-reused 0
Unpacking objects: 100% (17/17), done.
Tapped 1 command (49 files, 59.5KB).
==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community)
5.mongoコマンドを打ってみる
xxxxxx-no-MBP:~ xxxxxx$ mongo
MongoDB shell version v4.0.9
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("8918730f-4190-4313-8e3c-78adb2cffb63") }
MongoDB server version: 4.0.9
Server has startup warnings:
2019-04-29T19:32:53.305+0900 I CONTROL [initandlisten]
2019-04-29T19:32:53.305+0900 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-04-29T19:32:53.305+0900 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-04-29T19:32:53.306+0900 I CONTROL [initandlisten]
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
6.データベースの中身を表示してみる
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
>
用語について
Formula: The package definition
Tap: A Git repository of Formulae and/or commands
参考
https://qiita.com/saa/items/85ed5e914d424fbf9fd6
https://qiita.com/wkentaro/items/d4981582e08b134f1e1d
http://tweeeety.hateblo.jp/entry/2018/05/04/181928