4

I installed MongoDB via Homebrew. Manually created the /data/db directory. Tried to run mongod command from Command Line, here's what happened :

Sanjeet-Suhags-MacBook-Pro:~ sanjeetsuhag$ mongod mongod --help for help and startup options 2014-04-24T09:18:12.949+0530 [initandlisten] MongoDB starting : pid=19900 port=27017 dbpath=/data/db 64-bit host=Sanjeet-Suhags-MacBook-Pro.local 2014-04-24T09:18:12.949+0530 [initandlisten] 2014-04-24T09:18:12.949+0530 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000 2014-04-24T09:18:12.949+0530 [initandlisten] db version v2.6.0 2014-04-24T09:18:12.949+0530 [initandlisten] git version: nogitversion 2014-04-24T09:18:12.949+0530 [initandlisten] build info: Darwin minimavericks.local 13.1.0 Darwin Kernel Version 13.1.0: Thu Jan 16 19:40:37 PST 2014; root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49 2014-04-24T09:18:12.949+0530 [initandlisten] allocator: tcmalloc 2014-04-24T09:18:12.949+0530 [initandlisten] options: {} 2014-04-24T09:18:12.949+0530 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating 2014-04-24T09:18:12.949+0530 [initandlisten] dbexit: 2014-04-24T09:18:12.949+0530 [initandlisten] shutdown: going to close listening sockets... 2014-04-24T09:18:12.949+0530 [initandlisten] shutdown: going to flush diaglog... 2014-04-24T09:18:12.949+0530 [initandlisten] shutdown: going to close sockets... 2014-04-24T09:18:12.950+0530 [initandlisten] shutdown: waiting for fs preallocator... 2014-04-24T09:18:12.950+0530 [initandlisten] shutdown: lock for final commit... 2014-04-24T09:18:12.950+0530 [initandlisten] shutdown: final commit... 2014-04-24T09:18:12.950+0530 [initandlisten] shutdown: closing all files... 2014-04-24T09:18:12.950+0530 [initandlisten] closeAllFiles() finished 2014-04-24T09:18:12.950+0530 [initandlisten] shutdown: removing fs lock... 2014-04-24T09:18:12.950+0530 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor 2014-04-24T09:18:12.950+0530 [initandlisten] dbexit: really exiting now Sanjeet-Suhags-MacBook-Pro:~ sanjeetsuhag$ 

What's going wrong ?

EDIT

Sanjeet-Suhags-MacBook-Pro:~ sanjeetsuhag$ ls -ld /data/db drwxr-xr-x 2 root wheel 68 Apr 24 09:15 /data/db Sanjeet-Suhags-MacBook-Pro:~ sanjeetsuhag$ whoami sanjeetsuhag Sanjeet-Suhags-MacBook-Pro:~ sanjeetsuhag$ 
2
  • 1
    what is the permissions on /data/db vs who is the user you are starting mongod process as? If that user doesn't have write permissions to the db directory this will happen. Commented Apr 24, 2014 at 4:05
  • do ls -ld /data/db and post the results. Then do whoami and post the result of that. It's not relevant whether the user you are running as has admin privileges or not. Commented Apr 24, 2014 at 4:15

3 Answers 3

7

The problem is that the files mongod is trying to write to are owned by root but you are running mongod as user sanjeetsuhag.

The correct fix would be to change ownership of the directory via command:

$ sudo chown -R sanjeetsuhag /data/db 

This will make the directory and everything under it owned by the same user you are running mongod as, which will allow it to start.

Sign up to request clarification or add additional context in comments.

1 Comment

sorry, you will need to run it with sudo
2

I have same issues. I installed MongoDB with homebrew.

I think it needs admin priveledges.

I used : sudo mongod and it worked fine for me. Please try it.

Comments

-1

{"t":{"$date":"2022-12-17T08:43:44.380+05:30"},"s":"I", "c":"NETWORK", "id":4915701, "ctx":"-","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":17},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":17},"outgoing":{"minWireVersion":6,"maxWireVersion":17},"isInternalClient":true}}} {"t":{"$date":"2022-12-17T08:43:44.383+05:30"},"s":"I", "c":"CONTROL", "id":23285, "ctx":"-","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"} {"t":{"$date":"2022-12-17T08:43:44.399+05:30"},"s":"I", "c":"NETWORK", "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."} {"t":{"$date":"2022-12-17T08:43:44.406+05:30"},"s":"I", "c":"REPL", "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","namespace":"config.tenantMigrationDonors"}} {"t":{"$date":"2022-12-17T08:43:44.406+05:30"},"s":"I", "c":"REPL", "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","namespace":"config.tenantMigrationRecipients"}} {"t":{"$date":"2022-12-17T08:43:44.406+05:30"},"s":"I", "c":"REPL", "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"ShardSplitDonorService","namespace":"config.tenantSplitDonors"}} {"t":{"$date":"2022-12-17T08:43:44.406+05:30"},"s":"I", "c":"CONTROL", "id":5945603, "ctx":"main","msg":"Multi threading initialized"} {"t":{"$date":"2022-12-17T08:43:44.407+05:30"},"s":"I", "c":"CONTROL", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":6806,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"sumanths-Mac-mini.local"}} {"t":{"$date":"2022-12-17T08:43:44.407+05:30"},"s":"I", "c":"CONTROL", "id":23352, "ctx":"initandlisten","msg":"Unable to resolve sysctl {sysctlName} (number) ","attr":{"sysctlName":"hw.cpufrequency"}} {"t":{"$date":"2022-12-17T08:43:44.407+05:30"},"s":"I", "c":"CONTROL", "id":23351, "ctx":"initandlisten","msg":"{sysctlName} unavailable","attr":{"sysctlName":"machdep.cpu.features"}} {"t":{"$date":"2022-12-17T08:43:44.407+05:30"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"6.0.1","gitVersion":"32f0f9c88dc44a2c8073a5bd47cf779d4bfdee6b","modules":[],"allocator":"system","environment":{"distarch":"aarch64","target_arch":"aarch64"}}}} {"t":{"$date":"2022-12-17T08:43:44.407+05:30"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"22.2.0"}}} {"t":{"$date":"2022-12-17T08:43:44.407+05:30"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}} {"t":{"$date":"2022-12-17T08:43:44.411+05:30"},"s":"I", "c":"NETWORK", "id":5693100, "ctx":"initandlisten","msg":"Asio socket.set_option failed with std::system_error","attr":{"note":"acceptor TCP fast open","option":{"level":6,"name":261,"data":"00 04 00 00"},"error":{"what":"set_option: Invalid argument","message":"Invalid argument","category":"asio.system","value":22}}} {"t":{"$date":"2022-12-17T08:43:44.415+05:30"},"s":"E", "c":"CONTROL", "id":20557, "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"NonExistentPath: Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."}} {"t":{"$date":"2022-12-17T08:43:44.415+05:30"},"s":"I", "c":"REPL", "id":4784900, "ctx":"initandlisten","msg":"Stepping down the ReplicationCoordinator for shutdown","attr":{"waitTimeMillis":15000}} {"t":{"$date":"2022-12-17T08:43:44.416+05:30"},"s":"I", "c":"REPL", "id":4794602, "ctx":"initandlisten","msg":"Attempting to enter quiesce mode"} {"t":{"$date":"2022-12-17T08:43:44.416+05:30"},"s":"I", "c":"-", "id":6371601, "ctx":"initandlisten","msg":"Shutting down the FLE Crud thread pool"} {"t":{"$date":"2022-12-17T08:43:44.416+05:30"},"s":"I", "c":"COMMAND", "id":4784901, "ctx":"initandlisten","msg":"Shutting down the MirrorMaestro"} {"t":{"$date":"2022-12-17T08:43:44.416+05:30"},"s":"I", "c":"SHARDING", "id":4784902, "ctx":"initandlisten","msg":"Shutting down the WaitForMajorityService"} {"t":{"$date":"2022-12-17T08:43:44.416+05:30"},"s":"I", "c":"NETWORK", "id":20562, "ctx":"initandlisten","msg":"Shutdown: going to close listening sockets"} {"t":{"$date":"2022-12-17T08:43:44.416+05:30"},"s":"I", "c":"NETWORK", "id":4784905, "ctx":"initandlisten","msg":"Shutting down the global connection pool"} {"t":{"$date":"2022-12-17T08:43:44.416+05:30"},"s":"I", "c":"CONTROL", "id":4784906, "ctx":"initandlisten","msg":"Shutting down the FlowControlTicketholder"} {"t":{"$date":"2022-12-17T08:43:44.416+05:30"},"s":"I", "c":"-", "id":20520, "ctx":"initandlisten","msg":"Stopping further Flow Control ticket acquisitions."} {"t":{"$date":"2022-12-17T08:43:44.416+05:30"},"s":"I", "c":"NETWORK", "id":4784918, "ctx":"initandlisten","msg":"Shutting down the ReplicaSetMonitor"} {"t":{"$date":"2022-12-17T08:43:44.416+05:30"},"s":"I", "c":"SHARDING", "id":4784921, "ctx":"initandlisten","msg":"Shutting down the MigrationUtilExecutor"} {"t":{"$date":"2022-12-17T08:43:44.416+05:30"},"s":"I", "c":"ASIO", "id":22582, "ctx":"MigrationUtil-TaskExecutor","msg":"Killing all outstanding egress activity."} {"t":{"$date":"2022-12-17T08:43:44.416+05:30"},"s":"I", "c":"COMMAND", "id":4784923, "ctx":"initandlisten","msg":"Shutting down the ServiceEntryPoint"} {"t":{"$date":"2022-12-17T08:43:44.417+05:30"},"s":"I", "c":"CONTROL", "id":4784925, "ctx":"initandlisten","msg":"Shutting down free monitoring"} {"t":{"$date":"2022-12-17T08:43:44.417+05:30"},"s":"I", "c":"CONTROL", "id":4784927, "ctx":"initandlisten","msg":"Shutting down the HealthLog"} {"t":{"$date":"2022-12-17T08:43:44.417+05:30"},"s":"I", "c":"CONTROL", "id":4784928, "ctx":"initandlisten","msg":"Shutting down the TTL monitor"} {"t":{"$date":"2022-12-17T08:43:44.417+05:30"},"s":"I", "c":"CONTROL", "id":6278511, "ctx":"initandlisten","msg":"Shutting down the Change Stream Expired Pre-images Remover"} {"t":{"$date":"2022-12-17T08:43:44.417+05:30"},"s":"I", "c":"CONTROL", "id":4784929, "ctx":"initandlisten","msg":"Acquiring the global lock for shutdown"} {"t":{"$date":"2022-12-17T08:43:44.417+05:30"},"s":"I", "c":"-", "id":4784931, "ctx":"initandlisten","msg":"Dropping the scope cache for shutdown"} {"t":{"$date":"2022-12-17T08:43:44.417+05:30"},"s":"I", "c":"CONTROL", "id":20565, "ctx":"initandlisten","msg":"Now exiting"} {"t":{"$date":"2022-12-17T08:43:44.417+05:30"},"s":"I", "c":"CONTROL", "id":23138, "ctx":"initandlisten","msg":"Shutting down","attr":{"exitCode":100}}

service state will start and end like this if we use sudo mongod

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.