1.添加mongo的仓库#
1  | brew tap mongodb/brew  | 
2.安装mongodb#
1  | brew install mongodb-community@4.4  | 
安装成功
3.打开mongo shell#
1  | /usr/local/opt/mongodb-community@4.4/bin/mongo xxx:27017/your_db  | 
如果是mongo 6.0的话,是没有mongo命令的,需要额外安装mongosh,下载地址
1  | https://www.mongodb.com/try/download/shell  | 
4.查询数据#
查看db
1  | show dbs  | 
如果遇到not master and slaveOk=false的报错,可以执行如下命令
1  | rs.slaveOk()  | 
如果遇到Error: Authentication failed的报错,可能是缺少了–authenticationDatabase admin参数
1  | /Users/lintong/Downloads/mongosh-1.9.1-darwin-x64/bin/mongosh mongodb://xxx:27017/test -u xxx --authenticationDatabase admin -p  | 
其他参数参考:https://www.mongodb.com/docs/mongodb-shell/reference/options/
查询数据
1  | db.getCollection("your_collection").find()  | 
查询一条数据
1  | db.getCollection("your_collection").findOne()  | 
