Golang + WebSocket + MongoDB 即时聊

2022-04-15  本文已影响0人  Y了个J

安装MongoDB

brew install mongodb-community@4.2

If you need to have mongodb-community@4.2 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/mongodb-community@4.2/bin:$PATH"' >> ~/.zshrc


To start mongodb/brew/mongodb-community@4.2 now and restart at login:
  brew services start mongodb/brew/mongodb-community@4.2
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.2/4.2.19: 21 files, 306.8MB, built in 9 seconds
==> Running `brew cleanup mongodb-community@4.2`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

安装完成生成文件如下:

下载目录:/usr/local/Cellar/mongodb-community@4.2
配置文件:/usr/local/etc/mongod.conf
日志目录路径:/usr/local/var/log/mongodb
数据目录路径:/usr/local/var/mongodb
mongod.conf路径:/usr/local/etc/mongod.conf

brew服务启动/关闭mongodb

brew services start mongodb-community@4.2
brew services stop mongodb-community@4.2

手动添加所需的文件夹

sudo mkdir -p /data/db         //根目录下
sudo mongod --dbpath=/data/db

配置mongod全局路径

//打开脚本
open -e .bash_profile 
//添加路径
export PATH=$PATH:$MONO_HOME/bin
export PATH=/usr/local/Cellar/mongodb-community@4.2/4.2.15/bin:$PATH
//Command+S保存配置
source .bash_profile //使配置生效
//测试
mongod -version //正常显示版本信息就是配置完成了

启动服务

sudo mongod 

终端使用mongodb

mongo

> show dbs
上一篇下一篇

猜你喜欢

热点阅读