我已经在我的 Mac 上安装了 MongoDB,但是该进程当前未运行。 如何启动 MongoDB 服务,以便我可以开始使用命令?
$ brew services start mongodb
/usr/local/etc/mongod.conf
中调整配置。 - Pierre-Alexis de Solminihacbrew services start mongodb-community
命令来启动 MongoDB。 - yco请在终端中尝试以下步骤:
which mongod
这将输出你的mongod
路径,但如果它不在$PATH
中,命令输出将为空。所以你需要找到可执行文件:
mongod
路径,但如果它未在$PATH
中,则命令输出将为空。因此,您需要查找可执行文件:find / -name 'mongod'
在此命令的输出中,您将看到许多行,其中之一将类似于bin/mongod
,例如/usr/local/mongodb/bin/mongod
。在这种情况下,请获取整个绝对路径并执行以下操作:echo "PATH=/usr/local/mongodb/bin/:$PATH" >> ~/.bash_profile
. ~/.bash_profile
然后再尝试一次:
mongod --dbpath /your/path
只需执行brew services start mongodb-community
。示例:
$ brew services list
Name Status User Plist
mongodb-community stopped
$ brew services start mongodb-community
==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community)
当然,这取决于您的安装方式。这是典型的Homebrew安装方式。现在是2021年,所以在Mac上启动mongodb
:
brew
brew services start mongodb-community
brew install mongodb-community
安装的MongoDB类似地:
brew services start mongodb-community@4.2
brew services install mongodb-community@4.2
安装的MongoDBstart
意味着启动并设置开机自启
只需运行当前版本,请使用run
:
brew services run mongodb-community
启动后,请使用以下命令检查状态:
brew services
对于mongodb
的旧版本,命令为mongod
:
mongodb
mongod --config /usr/local/etc/mongod.conf
/usr/local/etc/mongod.conf
mongod --dbpath /data
/data
是常见的mongodb数据库路径进入一个你想让mongodb存储所有数据库文件的文件夹并运行以下命令:
mongod --dbpath=.
mongod
不在您的$PATH
中。 - Sergio Tulentsev要启动mongodb,您只需要在终端上运行“mongod”命令。
使用Homebrew安装和运行MongoDB
打开终端应用程序并输入
brew update
更新Homebrew后
brew install mongodb-community@4.0
下载Mongo后,创建“db”目录。这是Mongo数据文件存放的位置。 您可以通过运行以下命令在默认位置创建目录
sudo mkdir -p /data/db
确保/data/db目录具有正确的权限,运行以下命令
sudo chown -R
id -un
/data/db
运行Mongo守护进程,在一个终端窗口中运行
brew services start mongodb-community
这将启动Mongo服务器。 运行Mongo shell,使用Mongo守护进程在一个终端中运行mongo。这将运行Mongo shell,一种访问MongoDB中的数据的应用程序。 要退出Mongo shell,请运行quit() 要停止Mongo守护进程,请按Ctrl-C键
启动服务:
brew services start mongo
https://treehouse.github.io/installation-guides/mac/mongo-mac.html
对于mongodb-community@4.2
启动请运行brew services start mongodb-community@4.2
停止请运行brew services stop mongodb-community@4.2
但是如果您不知道具体的版本号,可以省略指定版本号。
来源:链接
使用这行代码可以解决问题。
在mongo bin路径下,在终端中执行此行代码:
export PATH=<mongodb-install-directory>/bin:$PATH
<mongodb-install-directory>
请替换为您的路径,例如:
export PATH=/Application/Mongo/bin:$PATH
使用以下命令检查已安装的服务:
brew services list
也可以直接使用以下方式进行检查:
which mongod
brew services start <service_name>
例如:
如果服务名称是mongodb
brew services start mongodb
brew services start mongodb-community
针对特定版本:
如果已安装mongodb-community@4.4
brew services start mongodb-community@4.4
mongod
。 - w3debugger