Mongodb not working
-
@gotwf I have a little update on this.
Everywhere I can find, config files say that my data is and should be stored in/var/lib/mongodb
(it is) but when I typesudo mongod
in a terminal this is what it gives me:@hp-laptop-nodebb:~$ sudo mongod 2021-11-15T18:00:36.714-0500 I CONTROL [initandlisten] MongoDB starting : pid=201574 port=27017 dbpath=/data/db 64-bit host=hp-laptop-nodebb 2021-11-15T18:00:36.714-0500 I CONTROL [initandlisten] db version v3.6.8 2021-11-15T18:00:36.714-0500 I CONTROL [initandlisten] git version: 8e540c0b6db93ce994cc548f000900bdc740f80a 2021-11-15T18:00:36.714-0500 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1f 31 Mar 2020 2021-11-15T18:00:36.714-0500 I CONTROL [initandlisten] allocator: tcmalloc 2021-11-15T18:00:36.714-0500 I CONTROL [initandlisten] modules: none 2021-11-15T18:00:36.714-0500 I CONTROL [initandlisten] build environment: 2021-11-15T18:00:36.714-0500 I CONTROL [initandlisten] distarch: x86_64 2021-11-15T18:00:36.714-0500 I CONTROL [initandlisten] target_arch: x86_64 2021-11-15T18:00:36.714-0500 I CONTROL [initandlisten] options: {} 2021-11-15T18:00:36.714-0500 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating 2021-11-15T18:00:36.714-0500 I CONTROL [initandlisten] now exiting 2021-11-15T18:00:36.714-0500 I CONTROL [initandlisten] shutting down with code:100
Notice how it says
NonExistentPath: Data directory /data/db not found
yet all config files say it's in/var/lib/mongodb
. This is so confusing.Furthermore, now the service (mongodb.service) starts fine on its own,
@hp-laptop-nodebb:~$ sudo systemctl restart mongodb && sudo systemctl status mongodb ● mongodb.service - An object/document-oriented database Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2021-11-15 18:05:39 EST; 38ms ago Docs: man:mongod(1) Main PID: 201756 (mongod) Tasks: 1 (limit: 9367) Memory: 6.7M CGroup: /system.slice/mongodb.service └─201756 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf
only NodeBB can't connect to it
2021-11-15T22:45:56.110Z [4567/140436] - info: [app] Database connection closed. 2021-11-15T22:45:56.110Z [4567/140436] - info: [app] Shutdown complete. [cluster] Child Process (140436) has exited (code: 0, signal: null) 2021-11-15T22:46:00.292Z [4567/199420] - error: MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 at Timeout._onTimeout (/var/www/nbb/node_modules/mongodb/lib/sdam/topology.js:325:38) at listOnTimeout (internal/timers.js:557:17) at processTimers (internal/timers.js:500:7)
unless I have it open in a terminal window like before:
2021-11-15T23:08:00.807Z [4567/201950] - info: NodeBB is now listening on: 0.0.0.0:4567
if anyone would be interested in helping me and would like any additional logs, I'd be happy to provide them through PM's.
Thanks for helping
-
@dunlix Well, I do not use Ubuntu for long while now so cannot comment there. Mongodb Debian pkgs default to /var/lib/mongodb. The contents of wh/should look something akin to this:
root@mallard:~# ll /var/lib/mongodb/ total 421696 drwxr-xr-x 4 mongodb mongodb 4096 Nov 16 00:26 . drwxr-xr-x 32 root root 4096 Apr 12 2021 .. -rw------- 1 mongodb mongodb 47 Apr 11 2021 WiredTiger -rw------- 1 mongodb mongodb 21 Apr 11 2021 WiredTiger.lock -rw------- 1 mongodb mongodb 1455 Nov 16 00:26 WiredTiger.turtle -rw------- 1 mongodb mongodb 241664 Nov 16 00:26 WiredTiger.wt -rw------- 1 mongodb mongodb 36864 Nov 16 00:26 WiredTigerHS.wt -rw------- 1 mongodb mongodb 36864 Nov 3 01:53 _mdb_catalog.wt -rw------- 1 mongodb mongodb 36864 Nov 3 01:53 collection-0--6779710148686833028.wt -rw------- 1 mongodb mongodb 4096 Nov 3 01:52 collection-0--8716107555814307976.wt -rw------- 1 mongodb mongodb 114978816 Nov 3 01:51 collection-0-7297207552526326231.wt -rw------- 1 mongodb mongodb 223993856 Nov 16 00:26 collection-10--6779710148686833028.wt -rw------- 1 mongodb mongodb 36864 Nov 3 01:52 collection-11--6779710148686833028.wt -rw------- 1 mongodb mongodb 32768 Nov 3 01:52 collection-13--6779710148686833028.wt -rw------- 1 mongodb mongodb 32768 Nov 3 01:52 collection-15--6779710148686833028.wt -rw------- 1 mongodb mongodb 12288 Nov 3 01:52 collection-17--6779710148686833028.wt
The db location is configured in /etc/mongod.conf:
root@mallard:~# grep -i db /etc/mongod.conf # http://docs.mongodb.org/manual/reference/configuration-options/ dbPath: /var/lib/mongodb
I would expect Ubuntu to be same. Use systemctl to stop and start mongodb service. Check the mongo server via systemctl status.
root@mallard:~# systemctl status mongod ● mongod.service - MongoDB Database Server Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2021-11-03 01:51:58 UTC; 1 weeks 5 days ago Docs: https://docs.mongodb.org/manual Main PID: 573 (mongod) Memory: 208.2M CGroup: /system.slice/mongod.service └─573 /usr/bin/mongod --config /etc/mongod.conf
If running and all reports back dandy confirm it is listening on port 27017:
root@mallard:~# netstat -na | grep 27017 tcp 0 0 192.168.128.121:27017 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN tcp 0 0 192.168.128.121:38624 192.168.128.121:27017 ESTABLISHED tcp 0 0 192.168.128.121:37938 192.168.128.122:27017 ESTABLISHED tcp 0 0 192.168.128.121:27017 192.168.128.122:56238 ESTABLISHED tcp 0 0 192.168.128.121:33606 192.168.128.123:27017 ESTABLISHED
But I got a feelin' that yours is not and only listening via unix socket. So please check mongo's "Net" settings in /etc/mongod.conf:
# network interfaces net: port: 27017 bindIp: 127.0.0.1
NodeBB should now be able to talk to MongoDB. Start it from CLI with logging.
-
@dunlix I believe
/data/db
is just the default placeholder, so that is why it is trying to access it. You've executedmongod
on its own with no flags, so it assumes the default config options, since it doesn't know where to locate the config file at/etc/mongod.conf
That said, on Ubuntu the logs are kept at
/var/log/mongodb/mongodb.log
Can you
tail -F /var/log/mongodb/mongodb.log
and then in another terminalsudo systemctl start mongodb
? -
@dunlix said in Mongodb not working:
I looked around and realized that it wasn’t loading the confit file or something,
Hmmm..... I wonder... Reaching here but perchance might your mongod.conf file have become corrupted in some manner? You said all you did was a system upgrade and that should not have touched mongod.conf on a running system. But one never knows....
Also, along related note, mongod.conf is ASCII text only. No UTF-8. So if your text editor somehow slipped a little utf-8 in there during some edit, but you did not reboot until the update, and then/now mongod can no longer read/load mongod.conf? Maybe, just maybe?
But mainly in the main, need to confirm mongod is indeed listening on localhost port 27017.
-
@gotwf said in Mongodb not working:
But mainly in the main, need to confirm mongod is indeed listening on localhost port 27017.
Yes it is cause when I start it the right way I only specify the dbpath and NodeBB can connect right away.
-
@dunlix It would be beneficial to confirm APT-Sources, e.g.;
APT-Sources: http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4/main amd64 Packages Description: MongoDB shell client
Note the repo.mongodb.org bit above. Preferential to use mongo built pkgs if available. And they should be for Ubuntu. But maybe not set as default? So just confirm this bit for me whilst at it, eh?
-
-
@macfan said in Mongodb not working:
@julian wouldnt be easier for nodeBB to just switch from this shitty DB engine to something more " modern "?
Hmm....
-
What would you propose?
-
Got code?
-
-
NodeBB supports postgresql.
-
@pitaj said in Mongodb not working:
NodeBB supports postgresql.
And, despite the above saga, Mongo itself was pretty groovy until someone got the bright idea to relicense it under SSPL. This has not affected me so much but seems to have hit a sore spot with various package managers.
-
@gotwf said in Mongodb not working:
Hmm....
- What would you propose?
- Got code?
- Something SQL maybe? Like mysql? I would touch nothing thats licensed on
SSPL
- What kind of code?