Arijit Roy
Arijit Roy

Reputation: 31

Can't change dbpath for mongodb

I'm unable to change dbpath for mongoDB (WSL2 Arch), I run the bellow command:

 sudo mongod --dbpath /home/arijit/work/data/

Permission for data folder:

drwxr-xr-x  2 mongodb mongodb 4096 Aug  9 10:00 data/

Error message I'm getting:

{"t":{"$date":"2020-08-09T11:55:45.163+05:30"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2020-08-09T11:55:45.228+05:30"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-08-09T11:55:45.229+05:30"},"s":"I",  "c":"NETWORK",  "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
{"t":{"$date":"2020-08-09T11:55:45.231+05:30"},"s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":2643,"port":27017,"dbPath":"/home/arijit/work/data/","architecture":"64-bit","host":"ARIJIT-PC-wsl"}}
{"t":{"$date":"2020-08-09T11:55:45.231+05:30"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.0","gitVersion":"563487e100c4215e2dce98d0af2a6a5a2d67c5cf","openSSLVersion":"OpenSSL 1.1.1g  21 Apr 2020","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu1804","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2020-08-09T11:55:45.231+05:30"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Arch","version":"rolling"}}}
{"t":{"$date":"2020-08-09T11:55:45.232+05:30"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"storage":{"dbPath":"/home/arijit/work/data/"}}}}
{"t":{"$date":"2020-08-09T11:55:45.268+05:30"},"s":"E",  "c":"STORAGE",  "id":20568,   "ctx":"initandlisten","msg":"Error setting up listener","attr":{"error":{"code":9001,"codeName":"SocketException","errmsg":"Address already in use"}}}
{"t":{"$date":"2020-08-09T11:55:45.389+05:30"},"s":"I",  "c":"CONTROL",  "id":20565,   "ctx":"initandlisten","msg":"Now exiting"}
{"t":{"$date":"2020-08-09T11:55:45.389+05:30"},"s":"I",  "c":"CONTROL",  "id":23138,   "ctx":"initandlisten","msg":"Shutting down","attr":{"exitCode":48}}

I have tried to delete /var/lib/mongodb/mongod.lock file and then run the command for change dbpath but same result.

Upvotes: 2

Views: 5068

Answers (2)

Isaac Oluwatemilorun
Isaac Oluwatemilorun

Reputation: 576

Based on @Gibbs answer, the error means the port is already in use another process. You can check and confirm this with

ps aux | grep -v grep | grep mongod

The output should look like this

user 73044   0.2  0.2  5501992  17176   ??  S    11:02AM   0:07.32 mongod --config /usr/local/etc/mongod.conf --fork

where 73044 is the PID

You can then kill the process with

kill -9 <PID> # Replace <PID> with the PID provided in the output...in my case 73044

You can now try starting mongod again with

mongod --dbpath /home/arijit/work/data/

Upvotes: 10

Gibbs
Gibbs

Reputation: 22964

Error is different

{"error":{"code":9001,"codeName":"SocketException","errmsg":"Address already in use"}}}

It means port is already being used by another process.

Try checking ps -ef | grep portConfigured. Default mongo port is 27017

If another process is running in the port, then you have to change port by passing --port portNumber while starting mongo.

Upvotes: 2

Related Questions