MongoDB error: mkdir: /data/db: Read-only file system

created at 08-24-2021 views: 255

description

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.

solution

method1

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.

mehod2

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
created at:08-24-2021
edited at: 08-24-2021: