For macOS users to fix this issue:
You need to go through the following steps:
Create the “db” directory. This is where the Mongo data files will live. You can create the directory in the default location by running:
sudo mkdir -p /data/db
Make sure that the /data/db
directory has the right permissions by running:
sudo chown -R `id -un` /data/db
You're all set now and you can run sudo mongod
to start the Mongo server.
It's not working if you run only mongod