Golang + WebSocket + MongoDB 即时聊天

安装MongoDB

brew install [email protected]

If you need to have [email protected] first in your PATH, run:
  echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc


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

安装完成生成文件如下:

下载目录:/usr/local/Cellar/[email protected]
配置文件:/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 [email protected]
brew services stop [email protected]

手动添加所需的文件夹

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/[email protected]/4.2.15/bin:$PATH
//Command+S保存配置
source .bash_profile //使配置生效
//测试
mongod -version //正常显示版本信息就是配置完成了

启动服务

sudo mongod 

终端使用mongodb

mongo

> show dbs

你可能感兴趣的:(Golang + WebSocket + MongoDB 即时聊天)