1

So I'm newbie to learning react and node and thought of building something based on MERN stack - I installed mongodb using npm install -g mongodb then it says its installed - then to create data directory for Monogo to use I ran mkdir -p /data/db and the response is Permission Denied.

To solve this I tried to do Fixing /etc/sudoers file which hasn't led me anywhere either. Anyway when I run this command mongod it gives me shutting me down server message as below:

2019-03-29T13:30:02.772+1100 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-03-29T13:30:02.792+1100 I CONTROL  [initandlisten] MongoDB starting : pid=2962 port=27017 dbpath=/data/db 64-bit host=Farwas-MBP
2019-03-29T13:30:02.792+1100 I CONTROL  [initandlisten] db version v4.0.3
2019-03-29T13:30:02.792+1100 I CONTROL [initandlisten] git version: 7ea530946fa7880364d88c8d8b6026bbc9ffa48c
2019-03-29T13:30:02.792+1100 I CONTROL [initandlisten] allocator: system
2019-03-29T13:30:02.792+1100 I CONTROL [initandlisten] modules: none
2019-03-29T13:30:02.792+1100 I CONTROL [initandlisten] build environment:
2019-03-29T13:30:02.792+1100 I CONTROL [initandlisten] distarch: x86_64
2019-03-29T13:30:02.792+1100 I CONTROL [initandlisten] target_arch: x86_64
2019-03-29T13:30:02.792+1100 I CONTROL [initandlisten] options: {}
2019-03-29T13:30:02.792+1100 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
2019-03-29T13:30:02.793+1100 I CONTROL [initandlisten] now exiting
2019-03-29T13:30:02.793+1100 I CONTROL [initandlisten] shutting down with code:48
5
  • You can actually edit your question directly by clicking on the "edit" link beneath it. That's easier than putting a lot of things in comments.
    – nohillside
    Commented Mar 29, 2019 at 7:13
  • I may be wrong, but I don't think the sudoers file has anything to do with your problem. You get the Permission denied error because the user you are logged in to is not allowed to create the /data directory. Can you add a link to the instructions you are following in setting this up (something must have told you to do mkdir -p /data/db for instance), will be easier to understand where things go amiss that way.
    – nohillside
    Commented Mar 29, 2019 at 7:20
  • Sorry about that didn't know that... And the user Im signed in is the admin user - like it authorizes every change on the system then why Permission denied - I came across this one to setup monogdb and followed this. codingthesmartway.com/… Apparently my friend;s system gives the same response as per the link
    – fahz
    Commented Mar 29, 2019 at 7:52
  • You need to create the directory by running sudo mkdir -p /data/db (and enter your password again when prompted).
    – nohillside
    Commented Mar 29, 2019 at 8:18
  • But from looking at the log output it seems that there is already a mongodb service running (Failed to set up listener: SocketException: Address already in use). Can you check whether this is the case, and then kill this process first?
    – nohillside
    Commented Mar 29, 2019 at 8:20

1 Answer 1

1

Use homebrew to install mongodb so you don’t need root would be my help to offer.

Then

brew install mongodb
brew services start mongodb 

As to sudoers, boot into recovery and use terminal (utilities menu) to mount the filesystem and fix it per this answer from your linked question. Older os can use single user mode, but terminal in recovery is nicer to use.

3
  • nop - it still shuts down the server - the sudo fixes is all done but it doesn't let me in - keeps telling me Permission Denied - im hopeless
    – fahz
    Commented Mar 29, 2019 at 2:32
  • How about posting the contents (or paste bin / gist) of tail -8 /usr/local/var/log/mongodb/mongo.log (and if you haven’t created the folder where the databases get stores - then try mkdir -p /usr/local/var/mongodb )
    – bmike
    Commented Mar 29, 2019 at 3:10
  • Restart that computer - you have another process that has claimed the port needed by mongod process - this has nothing to do with permissions. Excellent work getting to the actual problem by looking at the logs @fahz
    – bmike
    Commented Mar 29, 2019 at 14:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .