I got this error when creating a database storage directory /data/db
:
sudo mkdir -p /data/db
Then it reported the error mkdir: /data/db: Read-only file system
.
manually create the folder /data
and folder /db
with the path structure /data/db
,
then cd
into /db
, execute sudo mongod --dbpath=/usr/local/data/db
to start mongod
and set the database path.
We use the ~/data
folder as the database directory instead of the /data/db
folder
//enter ~/data
$ cd ~/data
//view the path
$ pwd
/Users/xuzhaoning/data
Specify the MongoDB database path
//change this path to your own
$ sudo mongod --dbpath=/Users/xuzhaoning/data