我最近完成了 Mongo 大学的 m001 基础课程,使用连接字符串连接到 Atlas 没有问题。通过实验,我搞砸了,现在我无法启动 mongo。我遵循的步骤是(从我的根目录):
brew doctor --verbose确保 Homebrew 正常运行并且没有问题。
HomeBrew 版本:3.0.1,
macOS : 11.1 ,
Homebrew Cask 暂存位置:/usr/local/Caskroom
Homebrew Cask Taps : /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask (3823 桶)
/usr/bin/xattr
brew cleanup
brew update
brew tap mongodb/brew
Mongo 文档安装
brew install mongodb-community@4.4
已下载:/Users/kevinturney/Library/Caches/Homebrew/downloads/269692f6b2d908000ecd7602021f4826947a782576c1fea760d25ece5ccbb521--mongodb-64-x4gz4
brew services start mongodb-community@4.4服务mongodb-community已经启动,用于brew services restart mongodb-community重启。
brew services restart mongodb-community==> 成功停止mongodb-community(标签:homebrew.mxcl.mongodb-community)
==> 成功启动mongodb-community(标签:homebrew.mxcl.mongodb-community)
brew services list这是错误:
| 姓名 | 地位 | 用户 | 列表 |
|---|---|---|---|
| mongodb-社区 | 错误 | 凯文图尼 | /Users/kevinturney/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist |
| mysql | 停止 | ||
| PostgreSQL | 停止 | ||
| Redis | 停止 | ||
| 未绑定 | 停止 |
我检查了进程,
ps -ef | grep mongo501 10770 81999 0 10:34AM ttys007 0:00.00 grep mongo
ps -ef | grep mongod501 10776 81999 0 10:34AM ttys007 0:00.00 grep mongod
ps -ef | grep mongos01 10781 81999 0 10:34AM ttys007 0:00.00 grep mongos
mongo --versionMongoDB shell 版本 v4.2.2
git 版本:a0bbbff6ada159e19298d37946ac8dc4b497eadf
分配器:系统
模块:企业
构建环境:
distarch:x86_64
target_arch:x86_64
mongod --versiondb 版本 v4.2.2
git 版本:a0bbbff6ada159e19298d37946ac8dc4b497eadf
分配器:系统
模块:企业
构建环境:
distarch:x86_64
target_arch:x86_64
当我运行 brew services start mongodb-community它成功启动然后
mongo 这是结果:
kevinturney / $ brew services start mongodb-community
==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community)
kevinturney / $ mongo
MongoDB shell version v4.2.2<br/>
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb<br/>
2021-02-17T11:37:32.192-0500 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, <br/>connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:341:17<br/>
@(connect):2:6
2021-02-17T11:37:32.195-0500 F - [main] exception: connect failed
2021-02-17T11:37:32.195-0500 E - [main] exiting with code 1
Run Code Online (Sandbox Code Playgroud)
我遵循了一个非常相似的StackOverflow 问题,通过 mongo 文档,卸载,重新安装,另外,尝试了这篇很棒的帖子,我不知道接下来要尝试什么。
如果您使用的是 macOS Catalina / BigSur 以上此修复程序将起作用:
转到命令行并执行这些命令,您需要使用 SUDO 否则这将不起作用。
我们首先删除文件夹mongodb,
sudo rm -rf /usr/local/var/mongodb
Run Code Online (Sandbox Code Playgroud)
然后,我们手动添加它,
cd /usr/local/var && mkdir mongodb
Run Code Online (Sandbox Code Playgroud)
现在,我们运行 brew 服务如下,请在最后提及 mongodb 版本,如下:
brew services start mongodb-community@5.0
Run Code Online (Sandbox Code Playgroud)
如果您收到以下响应,请重新启动服务,
Service `mongodb-community` already started, use `brew services restart mongodb-community` to restart.
Run Code Online (Sandbox Code Playgroud)
下面重启服务使用,请在最后提及mongodb版本:
brew services restart mongodb-community@5.0
Stopping `mongodb-community`... (might take a while)
==> Successfully stopped `mongodb-community` (label: homebrew.mxcl.mongodb-commu
==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-commu
Run Code Online (Sandbox Code Playgroud)
现在我们列出所有服务,使用以下命令:
brew services list
Run Code Online (Sandbox Code Playgroud)
输出:
Name Status User Plist
mongodb-community started xxx homebrew.mxcl.mongodb-community.plist
Run Code Online (Sandbox Code Playgroud)
打开您的终端并键入mongod –version以验证您的安装。