brew安装指定版本mongodb

1、安装mongo

#brew tap mongodb/brew

#@后跟版本号
brew install mongodb-community@4.2

2、启动/停用mongo

#启动mongo
brew services start mongodb-community@3.6

#停用mongo
brew services stop mongodb-community@3.6

3、mongo命令

#设置环境变量
vi ~/.bash_profile

#添加环境变量
export PATH=/usr/local/Cellar/mongodb/4.2/bin:$PATH

#重载配置
source ~/.bash_profile

#连接mongo
mongo

4、mongo基本操作


#创建数据库
use database;

#创建集合
db.createCollection('collection');

#插入数据
db.collection1.insertOne({id:1,name:'test'});

#查询数据
#查询所有数据
db.collection1.find();

#查询条件
db.collection1.find({id:'1'});

#删除数据
#删除所有数据
db.collection1.remove({});

#删除条件
db.collection1.remove({id:'1'});

EJR博客
请先登录后发表评论
  • latest comments
  • 总共0条评论