Monday, January 6, 2020

Error "Attempted to create a lock file on a read-only directory: /data/db, terminating" is displayed when start mongod

Problems
  • Try to start mongodb on my machine using the command below
 mongod
  • Error as shown below is displayed
...
2020-01-06T23:33:40.434-0600 I STORAGE  [initandlisten] exception in initAndListen: 
IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db, 
terminating
...

Solutions

  • Run the command below to grant the current user to have the write access to /data/db directory, it will work like a charm when you restart the mongodb again.
 sudo chown -R $USER /data/db

No comments: