Mac下安装mongodb
1.添加mongo的仓库
brew tap mongodb/brew
2.安装mongodb
brew install mongodb-community@4.4
安装成功
3.打开mongo shell
/usr/local/opt/mongodb-community@4.4/bin/mongo xxx:27017/your_db
如果是mongo 6.0的话,是没有mongo命令的,需要额外安装mongosh,下载地址
https://www.mongodb.com/try/download/shell
4.查询数据
查看db
show dbs
如果遇到not master and slaveOk=false的报错,可以执行如下命令
rs.slaveOk() 或者 rs.secondaryOk()
如果遇到Error: Authentication failed的报错,可能是缺少了--authenticationDatabase admin参数
/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/
查询数据
db.getCollection("your_collection").find()
查询一条数据
db.getCollection("your_collection").findOne()
本文只发表于博客园和tonglin0325的博客,作者:tonglin0325,转载请注明原文链接:https://www.cnblogs.com/tonglin0325/p/4583945.html