I set username and password in MongoDB every time I have to run this command in terminal:
sudo mongod --auth --port 27017 --dbpath /var/lib/mongodb
As soon as I close terminal, MongoDB db also closes so how will I set MongoDB in startup service?
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.Sign up to join this community
You need to use
sudo service to start MongoDB as a service, check the documentation for further details:
sudo service mongod --auth --port 27017 --dbpath /var/lib/mongodb
How to install on Ubuntu is handled extremely well in the MongoDB Docs so I won't rehash that here (plus it is updated more frequently than this answer will be).
Once you have installed MongoDB using that guide you can then modify the config file at
/etc/mongod.conf to reflect your desired config (auth etc.). Finally, you then start/stop the database with
sudo service mongod start and
sudo service mongod stop.