Home:ALL Converter>How to change mongodb data directory ubuntu

How to change mongodb data directory ubuntu

Ask Time:2022-11-23T01:20:36         Author:Nima shiri

Json Formatter

I want to change my mongodb data directory to my external media. I have done a lot of search and tried many ways, but could not achieve it. The problem is that when I change data dir to my media (other than home dir), it does not work, but it works for home dir:

I follow these steps:

sudo nano /etc/mongodb.conf

Then, changed:

# Where and how to store data.
storage:
  dbPath: /home/nimashiri/mongodb
#  engine:
#  wiredTiger:

Then:

sudo chown mongodb:mongodb /home/nimashiri/mongodb

When I try for my disk dir, it gives the following error:

● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2022-11-22 12:46:57 EST; 3s ago
       Docs: https://docs.mongodb.org/manual
    Process: 144014 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=100)
   Main PID: 144014 (code=exited, status=100)

Nov 22 12:46:57 nimashiri-G5-5000 systemd[1]: Started MongoDB Database Server.
Nov 22 12:46:57 nimashiri-G5-5000 systemd[1]: mongod.service: Main process exited, code=exited, status=100/n/a
Nov 22 12:46:57 nimashiri-G5-5000 systemd[1]: mongod.service: Failed with result 'exit-code'.

Any idea?

Author:Nima shiri,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/74536690/how-to-change-mongodb-data-directory-ubuntu
yy