Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run MongoDB using PM2

How do I run MongoDB using PM2? I'm using a Linux VPS (CentOS) and I tried doing this:

pm2 mongod

^ and that works but the problem is I need to bind IP and DBPath name

pm2 mongod -dbpath /home/[ommitted]/data/db --bind_ip [ommitted] -auth

^ But that doesn't work because of PM2 flags. So how can I run it using PM2 or at least make it so it doesn't shut down when I close the terminal

like image 965
Felix Isaac Avatar asked Jan 01 '26 07:01

Felix Isaac


1 Answers

You can create an SH file that runs the command, then run the SH file.

1. For example, name it "run.sh"
2. Open/edit file
3. Add this to the first line of the file mongod -dbpath /home/[ommitted]/data/db --bind_ip [ommitted] -auth
4. pm2 start run.sh

Another way that you can do is this;

pm2 start "mongod -dbpath /home/[ommitted]/data/db --bind_ip [ommitted] -auth"
like image 137
Felix Isaac Avatar answered Jan 03 '26 09:01

Felix Isaac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!