Before you start MongoDB for the first time, create the directory to which the mongod process will write data. By default, the mongod process uses the /data/db directory. If you create a directory other than this one, you must specify that directory in the dbpath option when starting the mongod process later in this procedure.
The following example command creates the default /data/db directory:
Mac 上下载 MongoDB
下载地址
下载地址
Copy the extracted archive to the target directory
Copy the extracted folder to the location from which MongoDB will run.
这里是将解压后的 MongoDB 文件放到将要运行的地方。推荐放在
/usr/local
。Ensure the location of the binaries is in the PATH variable.
The MongoDB binaries are in the bin/ directory of the archive. To ensure that the binaries are in your PATH, you can modify your PATH.
这里是要将 MongoDB 的二进制文件放入到环境变量中。由于我的终端是 Iterm + zsh,所以这边直接修改
.zshrc
文件Run MongoDB
Create the data directory
Before you start MongoDB for the first time, create the directory to which the mongod process will write data. By default, the mongod process uses the /data/db directory. If you create a directory other than this one, you must specify that directory in the dbpath option when starting the mongod process later in this procedure.
The following example command creates the default /data/db directory:
Set permissions fro the data directory
Before running mongod for the first time, ensure that the user account running mongod has read and write permissions for the directory.
给 /data/db 设置读写权限
mkdir -p /data/db 报错
执行
mkdir -p /data/db
报错,报错信息为:mkdir: /data/db: Read-only file system
。因为mac电脑默认是开启安全模式的,不能在根目录下面随便创建、删除文件夹。所以会出现这个错误。