MongoDB on macOS: How do I resolve chown: data/db: No such file or directory - mongodb

I installed MongoDB via Homebrew and created the /data/db directory.
When I run sudo chown -R id -un /data/db. I get this error:
chown: data/db: No such file or directory
I've tried all solutions I can find online and I see that the directory exists, but I am not sure what's going on. When I run mongod this is what I get:
Solomons-MacBook-Pro:expense-tracker Solomon$ mongod
{"t":{"$date":"2021-11-07T19:02:47.741-08:00"},"s":"I",
"c":"NETWORK", "id":4915701, "ctx":"-","msg":"Initialized wire
specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":13},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":13},"outgoing":{"minWireVersion":0,"maxWireVersion":13},"isInternalClient":true}}}
{"t":{"$date":"2021-11-07T19:02:47.747-08:00"},"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":"2021-11-07T19:02:47.748-08:00"},"s":"W", "c":"ASIO",
"id":22601, "ctx":"main","msg":"No TransportLayer configured during
NetworkInterface startup"}
{"t":{"$date":"2021-11-07T19:02:47.748-08:00"},"s":"I",
"c":"NETWORK", "id":4648602, "ctx":"main","msg":"Implicit TCP
FastOpen in use."}
{"t":{"$date":"2021-11-07T19:02:47.754-08:00"},"s":"W", "c":"ASIO",
"id":22601, "ctx":"main","msg":"No TransportLayer configured during
NetworkInterface startup"}
{"t":{"$date":"2021-11-07T19:02:47.756-08:00"},"s":"I", "c":"REPL",
"id":5123008, "ctx":"main","msg":"Successfully registered
PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","ns":"config.tenantMigrationDonors"}}
{"t":{"$date":"2021-11-07T19:02:47.756-08:00"},"s":"I", "c":"REPL",
"id":5123008, "ctx":"main","msg":"Successfully registered
PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","ns":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2021-11-07T19:02:47.756-08:00"},"s":"I",
"c":"CONTROL", "id":4615611, "ctx":"initandlisten","msg":"MongoDB
starting","attr":{"pid":3449,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"Solomons-MacBook-Pro.local"}}
{"t":{"$date":"2021-11-07T19:02:47.756-08:00"},"s":"I",
"c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build
Info","attr":{"buildInfo":{"version":"5.0.3","gitVersion":"657fea5a61a74d7a79df7aff8e4bcf0bc742b748","modules":[],"allocator":"system","environment":{"distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2021-11-07T19:02:47.756-08:00"},"s":"I",
"c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating
System","attr":{"os":{"name":"Mac OS X","version":"21.1.0"}}}
{"t":{"$date":"2021-11-07T19:02:47.756-08:00"},"s":"I",
"c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set
by command line","attr":{"options":{}}}
{"t":{"$date":"2021-11-07T19:02:47.758-08:00"},"s":"E",
"c":"NETWORK", "id":23024, "ctx":"initandlisten","msg":"Failed to
unlink socket
file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Permission
denied"}} {"t":{"$date":"2021-11-07T19:02:47.758-08:00"},"s":"F",
"c":"-", "id":23091, "ctx":"initandlisten","msg":"Fatal
assertion","attr":{"msgid":40486,"file":"src/mongo/transport/transport_layer_asio.cpp","line":960}}
{"t":{"$date":"2021-11-07T19:02:47.758-08:00"},"s":"F", "c":"-",
"id":23092, "ctx":"initandlisten","msg":"\n\n***aborting after
fassert() failure\n\n"}

I encountered this issue today. Try the following commands in order :
sudo mkdir -p /System/Volumes/Data/data/db --> This will create a new folder, as with the new Catalina OS, the root directory changed.
After this command, you will need to get write permissions.
sudo chown -R id -un /System/Volumes/Data/data/db
In order to finally open a mongo db connection, enter the following command:
sudo mongod --dbpath /System/Volumes/Data/data/db
For reference, use the following link: https://superuser.com/questions/1458974/macos-switched-root-mongodb-data-folder-to-system-ownership-and-it-cannot-be-cha

On your Mac, if you used Homebrew to install MongoDB, the data directory is created on installation. However, it is not data/db. Instead, on Intel Mac it is /usr/local/var/mongodb and on M1 Mac it is /opt/homebrew/var/mongodb.
To correctly install MongoDB using Homebrew (of course, check what's the latest version):
brew tap mongodb/brew
brew install mongodb-community#6.0
First, check that your MongoDB is running ok by listing the running services using brew:
brew services list
You should see something like:
Name Status User File
MongoDB-community started root
If not, try to stop, start or restart the service:
brew services stop mongodb/brew/mongodb-community
brew services start mongodb/brew/mongodb-community
brew services restart mongodb/brew/mongodb-community
For further information about the possible problems, check the log file:
tail $(brew --prefix)/var/log/mongodb/mongo.log
More details in the official documentation.

After Catalina the root folder is no longer writable.
So I created a folder on Desktop called MongoDB, and inside here the tmp & data/db.
And now I run it like this:
mongod --unixSocketPrefix ~/Desktop/MongoDB/tmp --dbpath ~/Desktop/MongoDB/data/db

Related

Running mongod service failed in Ubuntu 18.04.6

mongod service failed to start. After rebooting the machine, checking if mongod is allowed to read and write in the files/directories, I don't find the root of the issue.
Checking the service, it fails:
(base) avy#machine:~$ sudo service mongod status
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2022-08-07 14:16:22 CEST; 2min 20s ago
Docs: https://docs.mongodb.org/manual
Process: 5230 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=100)
Main PID: 5230 (code=exited, status=100)
août 07 14:16:22 machine systemd[1]: Started MongoDB Database Server.
août 07 14:16:22 machine systemd[1]: mongod.service: Main process exited, code=exited, status=100/n/a
août 07 14:16:22 machine systemd[1]: mongod.service: Failed with result 'exit-code'.
I looked if the database (dbPath storage) was still owned by mongod and it is:
(base) avy#machine:~$ ls -l
drwxrwxrwx 5 avy mongodb 4096 août 6 13:08 mongodatabases
My config file is very simple and I did not write on it since I used MongoDB for the first time:
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /home/avy/mongodatabases
journal:
enabled: true
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
It seemed it was due to 27017.sock:
(base) avy#machine:~$ mongo
MongoDB shell version v5.0.10
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017,
connection attempt failed:
SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:372:17
#(connect):2:6
exception: connect failed
exiting with code 1
I changed the owning:
(base) avy#machine:/tmp$ sudo chown mongodb:mongodb mongodb-27017.sock
(base) avy#machine:/tmp$ ls -l
srwx------ 1 mongodb mongodb 0 août 7 15:27 mongodb-27017.sock
it is still failling.
UPDATE, answer to rickhg12hs comment What's in /var/log/mongodb/mongod.log?
(base) avy#machine:/var/log/mongodb$ ls -l
total 112156
-rw------- 1 mongodb mongodb 114841063 août 7 17:37 mongod.log
There is only this file.
Does mongod still have an old lock file that needs to be deleted?
There is one in the desired dbPath:
(base) avy#machine:~/mongodatabases$ ls -l
...
-rw------- 1 mongodb mongodb 5 août 5 10:49 mongod.lock
...
I noticed something, let me know what you think about it
# the whole result of command
(base) avy#machine:~$ mongod
{"t":{"$date":"2022-08-07T17:37:43.960+02:00"},"s":"I", "c":"NETWORK", "id":4915701, "ctx":"thread1","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":13},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":13},"outgoing":{"minWireVersion":0,"maxWireVersion":13},"isInternalClient":true}}}
{"t":{"$date":"2022-08-07T17:37:43.960+02:00"},"s":"I", "c":"CONTROL", "id":23285, "ctx":"thread1","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2022-08-07T17:37:43.960+02:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"thread1","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2022-08-07T17:37:43.960+02:00"},"s":"I", "c":"NETWORK", "id":4648601, "ctx":"thread1","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
{"t":{"$date":"2022-08-07T17:37:43.962+02:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"thread1","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2022-08-07T17:37:43.962+02:00"},"s":"I", "c":"REPL", "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","ns":"config.tenantMigrationDonors"}}
{"t":{"$date":"2022-08-07T17:37:43.962+02:00"},"s":"I", "c":"REPL", "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","ns":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2022-08-07T17:37:43.962+02:00"},"s":"I", "c":"CONTROL", "id":5945603, "ctx":"thread1","msg":"Multi threading initialized"}
{"t":{"$date":"2022-08-07T17:37:43.962+02:00"},"s":"I", "c":"CONTROL", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":4638,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"machine"}}
{"t":{"$date":"2022-08-07T17:37:43.962+02:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"5.0.10","gitVersion":"bbf5bc7e16d1713c9349a09adf4901ca37472e66","openSSLVersion":"OpenSSL 1.1.1 11 Sep 2018","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu1804","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2022-08-07T17:37:43.962+02:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"18.04"}}}
{"t":{"$date":"2022-08-07T17:37:43.962+02:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2022-08-07T17:37:43.963+02:00"},"s":"E", "c":"NETWORK", "id":23024, "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Operation not permitted"}}
{"t":{"$date":"2022-08-07T17:37:43.963+02:00"},"s":"F", "c":"-", "id":23091, "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":40486,"file":"src/mongo/transport/transport_layer_asio.cpp","line":1019}}
{"t":{"$date":"2022-08-07T17:37:43.963+02:00"},"s":"F", "c":"-", "id":23092, "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}
When I focus on this line I saw it is still trying to run dbPath on /data/db contrary to what the config file tells:
{"t":{"$date":"2022-08-07T17:37:43.962+02:00"},"s":"I", "c":"CONTROL", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":4638,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"machine"}}
besides it says the connection to the socket 27017 is not permitted
{"t":{"$date":"2022-08-07T17:37:43.963+02:00"},"s":"E", "c":"NETWORK", "id":23024, "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Operation not permitted"}}
so I tried this:
(base) avy#machine:~$ sudo mongod --repair --config /etc/mongod.conf
But this is the same problem
UPDATE 2
What's in /lib/systemd/system/mongod.service?
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network-online.target
Wants=network-online.target
[Service]
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=/usr/bin/mongod --config /etc/mongod.conf
PIDFile=/var/run/mongodb/mongod.pid
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings
[Install]
WantedBy=multi-user.target
Does the tail of the contents of /var/log/mongodb/mongod.log have some enlightening messages?
I am not expert of database at all so "enlightening message" is difficult to judge for me. But I checked the behavior of a typical "good day" and the day it started to fail. I think this is due to a violent shutdown.
# a good day
{"t":{"$date":"2022-08-04T23:49:03.773+02:00"},"s":"I", "c":"CONTROL", "id":23138, "ctx":"SignalHandler","msg":"Shutting down","attr":{"exitCode":0}}
{"t":{"$date":"2022-08-05T10:49:00.638+02:00"},"s":"I", "c":"CONTROL", "id":20698, "ctx":"-","msg":"***** SERVER RESTARTED *****"}
# some lines
{"t":{"$date":"2022-08-05T10:49:00.651+02:00"},"s":"I", "c":"CONTROL", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":2027,"port":27017,"dbPath":"/home/avy/mongodatabases","architecture":"64-bit","host":"machine"}}
{"t":{"$date":"2022-08-05T10:49:00.651+02:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"5.0.10","gitVersion":"bbf5bc7e16d1713c9349a09adf4901ca37472e66","openSSLVersion":"OpenSSL 1.1.1 11 Sep 2018","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu1804","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2022-08-05T10:49:00.651+02:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"18.04"}}}
{"t":{"$date":"2022-08-05T10:49:00.651+02:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"config":"/etc/mongod.conf","net":{"bindIp":"127.0.0.1","port":27017},"processManagement":{"timeZoneInfo":"/usr/share/zoneinfo"},"storage":{"dbPath":"/home/avy/mongodatabases","journal":{"enabled":true}},"systemLog":{"destination":"file","logAppend":true,"path":"/var/log/mongodb/mongod.log"}}}}
{"t":{"$date":"2022-08-05T10:49:00.654+02:00"},"s":"I", "c":"STORAGE", "id":22270, "ctx":"initandlisten","msg":"Storage engine to use detected by data files","attr":{"dbpath":"/home/avy/mongodatabases","storageEngine":"wiredTiger"}}
I shutdown without issue but it seems that today the schema is different:
{"a":"7FEA0E67261F","b":"7FEA0E551000","o":"12161F","s":"clone","s+":"3F"}}} # you see no {"exitCode":0}
{"t":{"$date":"2022-08-07T08:56:02.403+02:00"},"s":"I", "c":"CONTROL", "id":20698, "ctx":"-","msg":"***** SERVER RESTARTED *****"}
... # some lines
{"t":{"$date":"2022-08-07T08:56:02.416+02:00"},"s":"I", "c":"CONTROL", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":1932,"port":27017,"dbPath":"/home/avy/mongodatabases","architecture":"64-bit","host":"machine"}}
{"t":{"$date":"2022-08-07T08:56:02.416+02:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"5.0.10","gitVersion":"bbf5bc7e16d1713c9349a09adf4901ca37472e66","openSSLVersion":"OpenSSL 1.1.1 11 Sep 2018","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu1804","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2022-08-07T08:56:02.416+02:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"18.04"}}}
{"t":{"$date":"2022-08-07T08:56:02.416+02:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"config":"/etc/mongod.conf","net":{"bindIp":"127.0.0.1","port":27017},"processManagement":{"timeZoneInfo":"/usr/share/zoneinfo"},"storage":{"dbPath":"/home/av/mongodatabases","journal":{"enabled":true}},"systemLog":{"destination":"file","logAppend":true,"path":"/var/log/mongodb/mongod.log"}}}}
and then the initandlisten operation started to fail.
Before mongod starts, there should be no lock file
I removed all .lock files related to mongo in the whole machine.
I tried once again repair command
(base) avy#machine:~$ mongod --repair --dbpath "/home/avy/mongodatabases"
{"t":{"$date":"2022-08-07T19:24:17.116+02:00"},"s":"I", "c":"NETWORK", "id":4915701, "ctx":"-","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":13},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":13},"outgoing":{"minWireVersion":0,"maxWireVersion":13},"isInternalClient":true}}}
{"t":{"$date":"2022-08-07T19:24:17.116+02:00"},"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":"2022-08-07T19:24:17.117+02:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2022-08-07T19:24:17.117+02:00"},"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":"2022-08-07T19:24:17.118+02:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2022-08-07T19:24:17.118+02:00"},"s":"I", "c":"REPL", "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","ns":"config.tenantMigrationDonors"}}
{"t":{"$date":"2022-08-07T19:24:17.118+02:00"},"s":"I", "c":"REPL", "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","ns":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2022-08-07T19:24:17.118+02:00"},"s":"I", "c":"CONTROL", "id":5945603, "ctx":"main","msg":"Multi threading initialized"}
{"t":{"$date":"2022-08-07T19:24:17.119+02:00"},"s":"I", "c":"CONTROL", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":8346,"port":27017,"dbPath":"/home/avy/mongodatabases","architecture":"64-bit","host":"machine"}}
{"t":{"$date":"2022-08-07T19:24:17.119+02:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"5.0.10","gitVersion":"bbf5bc7e16d1713c9349a09adf4901ca37472e66","openSSLVersion":"OpenSSL 1.1.1 11 Sep 2018","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu1804","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2022-08-07T19:24:17.119+02:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"18.04"}}}
{"t":{"$date":"2022-08-07T19:24:17.119+02:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"repair":true,"storage":{"dbPath":"/home/avy/mongodatabases"}}}}
{"t":{"$date":"2022-08-07T19:24:17.123+02:00"},"s":"F", "c":"STORAGE", "id":28661, "ctx":"initandlisten","msg":"Unable to read the storage engine metadata file","attr":{"error":{"code":38,"codeName":"FileNotOpen","errmsg":"Failed to read metadata from /home/mongodatabases/storage.bson"}}}
{"t":{"$date":"2022-08-07T19:24:17.123+02:00"},"s":"F", "c":"-", "id":23091, "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":28661,"file":"src/mongo/db/storage/storage_engine_metadata.cpp","line":91}}
{"t":{"$date":"2022-08-07T19:24:17.123+02:00"},"s":"F", "c":"-", "id":23092, "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}
About the version used:
(base) avy#machine:~$ mongod --version
db version v5.0.10
Build Info: {
"version": "5.0.10",
"gitVersion": "bbf5bc7e16d1713c9349a09adf4901ca37472e66",
"openSSLVersion": "OpenSSL 1.1.1 11 Sep 2018",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "ubuntu1804",
"distarch": "x86_64",
"target_arch": "x86_64"
}
}

How to populate the database for latest MongoDB Docker image?

Recently, I'm unable to launch a docker container based off the mongo image via my old set of command:
docker run -d --rm -v ${PWD}/mydb_data:/data/db --name db mongo
I noticed that the mongo images now have a preexisting but empty /data/db directory. Every time I try to populate some files into this /data/db directory within a container, the container fails and exits automatically. My first question is: are there any quick fix to this problem that I missed?
For clarification, my mydb_data directory contains .index files and .wt files etc. (And as a side comment, I got this directory handed over from a previous colleague so I'm still trying to understand the setup more.)
A second question is: is it normal that I'm receiving a stream of log outputs like below as I try to populate mongo db inside the docker container via an alternative set of commands that attempts to create a differently named new database through docker run -it -v ${PWD}/mydb_data:/data/db2 --name db2 mongo?
{"t":{"$date":"2021-08-13T18:29:32.246+00:00"},"s":"I", "c":"CONTROL", "id":23285, "ctx":"thread1","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2021-08-13T18:29:32.246+00:00"},"s":"I", "c":"NETWORK", "id":4915701, "ctx":"thread1","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":13},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":13},"outgoing":{"minWireVersion":0,"maxWireVersion":13},"isInternalClient":true}}}
{"t":{"$date":"2021-08-13T18:29:32.247+00:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"thread1","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2021-08-13T18:29:32.247+00:00"},"s":"I", "c":"NETWORK", "id":4648601, "ctx":"thread1","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
{"t":{"$date":"2021-08-13T18:29:32.248+00:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"thread1","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2021-08-13T18:29:32.248+00:00"},"s":"I", "c":"REPL", "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","ns":"config.tenantMigrationDonors"}}
{"t":{"$date":"2021-08-13T18:29:32.248+00:00"},"s":"I", "c":"REPL", "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","ns":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2021-08-13T18:29:32.249+00:00"},"s":"I", "c":"CONTROL", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":1,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"6e3da962aee5"}}
..........
My attempt to create a new mongo db has been going on for some hour, so I hope to check if this is on the right track.
Thanks!
From the Mongo - Official Image
Initializing a fresh instance
When a container is started for the first time it will execute files with extensions .sh and .js that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. .js files will be executed by mongo using the database specified by the MONGO_INITDB_DATABASE variable, if it is present, or test otherwise. You may also switch databases within the .js script.

how can i execute mongodb without connection issue on my mac?

i wrote it to download mongodb in my mac
$ brew tap mongodb/brew
$ brew install mongodb-community#4.4
$ brew services start mongodb-community#4.4
then after i type mongodand mongo, terminal showed it.
mongod
{"t":{"$date":"2021-04-24T14:39:55.881+09:00"},"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":"2021-04-24T14:39:55.884+09:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2021-04-24T14:39:55.884+09:00"},"s":"I", "c":"NETWORK", "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2021-04-24T14:39:55.885+09:00"},"s":"I", "c":"STORAGE", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":20966,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"1111ui-MacBookPro-2.local"}}
{"t":{"$date":"2021-04-24T14:39:55.885+09:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.4","gitVersion":"8db30a63db1a9d84bdcad0c83369623f708e0397","modules":[],"allocator":"system","environment":{"distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2021-04-24T14:39:55.885+09:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"20.3.0"}}}
{"t":{"$date":"2021-04-24T14:39:55.885+09:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2021-04-24T14:39:55.886+09:00"},"s":"E", "c":"NETWORK", "id":23024, "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Permission denied"}}
{"t":{"$date":"2021-04-24T14:39:55.886+09:00"},"s":"F", "c":"-", "id":23091, "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":40486,"file":"src/mongo/transport/transport_layer_asio.cpp","line":919}}
{"t":{"$date":"2021-04-24T14:39:55.886+09:00"},"s":"F", "c":"-", "id":23092, "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}
mongo
MongoDB shell version v4.4.4
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6
exception: connect failed
exiting with code 1
how can i solve this issue plz help me ...!

Mongod aborts on Mac

When I try to start mongod on my Mac I get the following error in the log file:
{"t":{"$date":"2020-08-24T16:29:32.041+03:00"},"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-24T16:29:32.044+03:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-08-24T16:29:32.044+03:00"},"s":"I", "c":"NETWORK", "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2020-08-24T16:29:32.045+03:00"},"s":"I", "c":"STORAGE", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":30381,"port":27017,"dbPath":"yourfolder","architecture":"64-bit","host":"Chaims-MacBook-Pro.local"}}
{"t":{"$date":"2020-08-24T16:29:32.045+03:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.0","gitVersion":"563487e100c4215e2dce98d0af2a6a5a2d67c5cf","modules":[],"allocator":"system","environment":{"distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2020-08-24T16:29:32.045+03:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"18.2.0"}}}
{"t":{"$date":"2020-08-24T16:29:32.045+03:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"storage":{"dbPath":"yourfolder"},"systemLog":{"destination":"file","logAppend":true,"path":"myfile.log"}}}}
{"t":{"$date":"2020-08-24T16:29:32.047+03:00"},"s":"E", "c":"NETWORK", "id":23024, "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Permission denied"}}
{"t":{"$date":"2020-08-24T16:29:32.047+03:00"},"s":"F", "c":"-", "id":23091, "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":40486,"file":"src/mongo/transport/transport_layer_asio.cpp","line":919}}
{"t":{"$date":"2020-08-24T16:29:32.047+03:00"},"s":"F", "c":"-", "id":23092, "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}
Any idea what the problem is?
Please use one of the following solutions.
for Linux
$ sudo rm -rf /tmp/mongodb-27017.sock
$ sudo service mongod start
for Mac
$ sudo rm -rf /tmp/mongodb-27017.sock
$ sudo brew services restart mongod
I had the same problem and this worked for me.
sudo mongod

MongoDB-Community not starting on Mac and giving errors

I am writing to inform that i had installed mongodb-community some time back using brew (High Sierra) and it was running. Then recently i upgraded and it doesn't seem to wire up. When i am running mongo in terminal, I am getting error:
MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:362:17
#(connect):2:6
exception: connect failed
exiting with code 1
When i checked logs for starting the mongodb-community service, I am getting following error:
{"t":{"$date":"2020-09-04T21:01:35.015-07:00"},"s":"W", "c":"CONTROL", "id":20698, "ctx":"main","msg":"***** SERVER RESTARTED *****","tags":["startupWarnings"]}
{"t":{"$date":"2020-09-04T21:01:35.021-07:00"},"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-09-04T21:01:35.027-07:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-09-04T21:01:35.027-07:00"},"s":"I", "c":"NETWORK", "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2020-09-04T21:01:35.028-07:00"},"s":"I", "c":"STORAGE", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":58706,"port":27017,"dbPath":"/Users/my_username/homebrew/var/mongodb","architecture":"64-bit","host":"SC-*"}}
{"t":{"$date":"2020-09-04T21:01:35.029-07:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.0","gitVersion":"563487e100c4215e2dce98d0af2a6a5a2d67c5cf","modules":[],"allocator":"system","environment":{"distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2020-09-04T21:01:35.029-07:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"17.7.0"}}}
{"t":{"$date":"2020-09-04T21:01:35.029-07:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"config":"/Users/my_username/homebrew/etc/mongod.conf","net":{"bindIp":"127.0.0.1"},"storage":{"dbPath":"/Users/my_username/homebrew/var/mongodb"},"systemLog":{"destination":"file","logAppend":true,"path":"/Users/my_username/homebrew/var/log/mongodb/mongo.log"}}}}
{"t":{"$date":"2020-09-04T21:01:35.038-07:00"},"s":"I", "c":"STORAGE", "id":22270, "ctx":"initandlisten","msg":"Storage engine to use detected by data files","attr":{"dbpath":"/Users/my_username/homebrew/var/mongodb","storageEngine":"wiredTiger"}}
{"t":{"$date":"2020-09-04T21:01:35.038-07:00"},"s":"I", "c":"STORAGE", "id":22315, "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=7680M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],"}}
{"t":{"$date":"2020-09-04T21:01:36.177-07:00"},"s":"W", "c":"STORAGE", "id":22347, "ctx":"initandlisten","msg":"Failed to start up WiredTiger under any compatibility version. This may be due to an unsupported upgrade or downgrade."}
{"t":{"$date":"2020-09-04T21:01:36.178-07:00"},"s":"F", "c":"STORAGE", "id":28595, "ctx":"initandlisten","msg":"Terminating.","attr":{"reason":"45: Operation not supported"}}
{"t":{"$date":"2020-09-04T21:01:36.178-07:00"},"s":"F", "c":"-", "id":23091, "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":28595,"file":"src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp","line":1100}}
{"t":{"$date":"2020-09-04T21:01:36.178-07:00"},"s":"F", "c":"-", "id":23092, "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}
Can i please seek your help in fixing this? I am not having sudo rights and can't upgrade the OS, but am open to use mongo using any method
similar issue, final worked solution:
uninstall (latest, but not worked version: 4.4.3)
brew uninstall mongodb-community
reinstall, old but worked 4.2.1
brew install mongodb-community#4.2
run
for now: brew services run mongodb-community#4.2
for now and set bootable: brew services start mongodb-community#4.2
check status
brew services
The log is telling you what is going on
"Failed to start up WiredTiger under any compatibility version. This may be due to an unsupported upgrade or downgrade."
So you may want to read documentation of your old mongoDB version to see if it is upgradeable to version 4.4.0, if it is not, consider upgrading to a most recent version that is compatible with the WiredTiger version you are currently using
This link might be useful. To upgrade to mongoDB v4.0 or above you must be running at least mongoDB v3.6, otherwise you will have to to upgrade to v3.6 first
uninstall mongodb
remove /var/lib/mongodb/ # because WiredTiger was not uninstalled cleanly
reinstall mongodb
Had same issue it occurred when my mongodb docker container restarted. What I did was remove mongod.lock its in the root folder where database data is stored.
Try the following steps:
first copy your database folder to be sure you have a backup.
then execute the following command:
mongod --dbpath /data/db --repair
check now if it works, if it still does not work
try to temporarily move the mongod.lock to some other location to test if the mongod.lock is causing the issue. Start mongodb and check if it works. If it does not you should downgrade.
To downgrade to the correct version you can do the following:
bsondump mongo/diagnostic.data/metrics.2021-10-06T08-41-05Z-00000 | jq -s '.[] | select(.type == {"$numberInt": "0"})| .doc.buildInfo.version'
Keep in mind that the metrics file can have a different date this is just an example.
After you have the version you can start your container with that specific version and it should work.