macOS上的MongoDB:如何解析chown:data/db:没有这样的文件或目录



我通过Homebrew安装了MongoDB,并创建了/data/db目录。

当我运行sudo chown -R id -un /data/db。我得到这个错误:

chown:data/db:没有这样的文件或目录

我已经尝试了我能在网上找到的所有解决方案,我看到目录存在,但我不确定发生了什么。当我运行mongod时,我得到的是:

Solomons MacBook Pro:费用跟踪器Solomon$mongod{"t":{"$date":"2021-11-07T19:02:47.741-08:00"};s":"I";,"c":"网络"id":4915701;ctx":&quot-&"msg":"初始化的导线"说明书"attr":{规范:{incomingExternalClient:{minWireVersion:0,maxWireVersion:13};incomingInternalClient":{"minWireVersion":0,"maxWireVersion";:13},";"传出":{"minWireVersion":0,"maxWireVersion";:13},";isInternalClient":true}}{"t":{"$date":"2021-11-07T19:02:47.747-08:00"};s":"I";,"c":"CONTROL"id":23285;ctx":"main"msg":"自动地禁用TLS 1.0,要强制启用TLS 1.0,请指定--sslDisabledProtocols"none"}{"t":{"$date":"2021-11-07T19:02:47.748-08:00"};s":"W"c":"ASIO">
"id":22601,";ctx":"main"msg":"期间未配置传输层NetworkInterface启动"}{"t":{"$date":"2021-11-07T19:02:47.748-08:00"};s":"I";,"c":"网络"id":4648602,";ctx":"main"msg":"隐式TCPFastOpen正在使用中"}{"t":{"$date":"2021-11-07T19:02:47.754-08:00"};s":"W"c":"ASIO">
"id":22601,";ctx":"main"msg":"期间未配置传输层NetworkInterface启动"}{"t":{"$date":"2021-11-07T19:02:47.756-08:00"};s":"I"c":"REPL">
"id":5123008;ctx":"main"msg":"已成功注册PrimaryOnlyService"attr":{"服务":"租户迁移捐赠者服务","ns&":"配置租户迁移捐赠者"}{"t":{"$date":"2021-11-07T19:02:47.756-08:00"};s":"I"c":"REPL">
"id":5123008;ctx":"main"msg":"已成功注册PrimaryOnlyService"attr":{"服务":"租户迁移接收服务","ns":"config.tenantMigrationRecipients"}{"t":{"$date":"2021-11-07T19:02:47.756-08:00"};s":"I";,"c":"CONTROL"id":4615611;ctx":"initandlisten"msg":"MongoDB开始"attr":{"pid":3449,"端口":27017,"dbPath":"/data/db","体系结构":"64位","主机":"Solomons MacBook Pro.local"}}{"t":{"$date":"2021-11-07T19:02:47.756-08:00"};s":"I";,"c":"CONTROL"id":23403;ctx":"initandlisten"msg":"建筑Info"attr":{"buildInfo":{"版本":"5.0.3","gitVersion":"657fea5a61a74d7a79df7aff8e4bcf0bc742b748","模块":[],"分配器":"系统","环境":target_arch":"x86_64"}}}}{"t":{"$date":"2021-11-07T19:02:47.756-08:00"};s":"I";,"c":"CONTROL"id":51765;ctx":"initandlisten"msg":"操作系统"attr":{"操作系统":{"名称":"Mac os X","版本":"21.1.0"}}{"t":{"$date":"2021-11-07T19:02:47.756-08:00"};s":"I";,"c":"CONTROL"id":21951;ctx":"initandlisten"msg":"选项集通过命令行"attr":{"选项":{}}{"t":{"$date":"2021-11-07T19:02:47.758-08:00"};s":"E";,"c":"网络"id":23024;ctx":"initandlisten"msg":"未能取消套接字链接文件"attr":{"路径":"/tmp/mongodb-27017.sock","错误":"权限"被拒绝的{}}{"t":{"$date":"2021-11-07T19:02:47.758-08:00"};s":"F";,"c":&quot-&"id":23091,";ctx":"initandlisten"msg":"致命的断言"attr":{"消息id":40486,"文件":"src/mongo/transport_transport_layer_asio.cpp","行":960}}{"t":{"$date":"2021-11-07T19:02:47.758-08:00"};s":"F"c":&quot-&">
"id":23092;ctx":"initandlisten"msg":"\n\n***在之后中止fassert()失败\n\n"}

我今天遇到了这个问题。按顺序尝试以下命令:

sudo mkdir-p/System/Volumes/Data/db/db-->这将创建一个新的文件夹,与新的Catalina操作系统一样,根目录也发生了变化。

执行此命令后,您将需要获得写入权限。sudo chown-Rid -un/System/Volumes/Data/db/db

为了最终打开mongo-db连接,请输入以下命令:sudo mongod--dbpath/System/Volumes/Data/db/db


如需参考,请使用以下链接:https://superuser.com/questions/1458974/macos-switched-root-mongodb-data-folder-to-system-ownership-and-it-cannot-be-cha

在您的Mac上,如果您使用Homebrew安装MongoDB,则会在安装时创建数据目录。然而,它不是data/db。相反,在英特尔Mac上是/usr/local/var/mongodb,而在M1 Mac上则是/opt/homebrew/var/mongodb

要使用Homebrew正确安装MongoDB(当然,请查看最新版本):

brew tap mongodb/brew
brew install mongodb-community@6.0

首先,通过使用brew:列出正在运行的服务来检查MongoDB是否正常运行

brew services list

你应该看到这样的东西:

Name              Status  User File
MongoDB-community started root

如果没有,请尝试停止、启动或重新启动服务:

brew services stop mongodb/brew/mongodb-community
brew services start mongodb/brew/mongodb-community
brew services restart mongodb/brew/mongodb-community

有关可能出现的问题的更多信息,请查看日志文件:

tail $(brew --prefix)/var/log/mongodb/mongo.log

更多详细信息请参阅官方文件。

Catalina之后,根文件夹不再可写。所以我在Desktop上创建了一个名为MongoDB的文件夹,里面有tmp&data/db。

现在我这样运行它:

mongod --unixSocketPrefix ~/Desktop/MongoDB/tmp --dbpath ~/Desktop/MongoDB/data/db

最新更新