安装与卸载
安装
在Mac上使用homebrew安装
-
更新Homebrew的package数据库:
brew update
-
安装:
brew install mongodb
然后会出现下面这样
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/mongodb-3.4.4.sierra.bottle
Already downloaded: /Users/liangma/Library/Caches/Homebrew/mongodb-3.4.4.sierra.bottle.tar.gz
==> Pouring mongodb-3.4.4.sierra.bottle.tar.gz
==> Using the sandbox
==> Caveats
To have launchd start mongodb now and restart at login:
brew services start mongodb
Or, if you don't want/need a background service you can just run:
mongod --config /usr/local/etc/mongod.conf
==> Summary
- 查看所有homebrew所安装的软件
brew list
这时候在列表中会出现mongodb
xieyushengdeMacBook-Pro:~ xieyusheng$ brew list
autoconf icu4c libyaml openssl@1.1 watchman
automake libgpg-error mongodb pcre
coreutils libksba node pkg-config
flow libtool openssl readline
这就代表安装成功了
卸载:
我们这还是通过homebrew来卸载
brew uninstall mongodb
然后在查看brew list就不会出现mongdb的存在了
简单使用
- 启动mongodb
mongod --config /usr/local/etc/mongod.conf
- 新启动终端连接mdb
mongo
- 查看所有数据库
show dbs
- 创建数据库
use dataone
(使用就自动创建) - 查看当前数据库
db
- 给当前数据库添加数据
db.dataone.insert({"name":"xiaoming",age:12})
- 查数据
db.dataone.find()
备注:
mdb安装默认Mac安装路径:
/usr/local/mongodb