4

I've been trying to set up MongoDB on my Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-22-generic x86_64) VPS and I've been running into a few problems. I am running as a user on my server that has root access but not using the root account itself.

I started to notice the problem when I was executing db.createUser() on the admin database so I could add other users and I was getting this error: not authorized to execute command

So I then proceeded to uninstall and install again using the tutorial as provided on the website: https://docs.mongodb.com/v3.2/tutorial/install-mongodb-on-ubuntu/

Now when I'm on stage 2 Verify that MongoDB has started successfully on the Run MongoDB Community Edition section, that is I look at my output from the file /var/log/mongodb/mongod.log, I get the following:

2017-04-14T14:23:09.309+0200 I CONTROL  [main] ***** SERVER RESTARTED *****
2017-04-14T14:23:09.316+0200 I CONTROL  [initandlisten] MongoDB starting : pid=9691 port=27017 dbpath=/var/lib/mongodb 64-bit host=vps338741
2017-04-14T14:23:09.316+0200 I CONTROL  [initandlisten] db version v3.4.3
2017-04-14T14:23:09.316+0200 I CONTROL  [initandlisten] git version: f07437fb5a6cca07c10bafa78365456eb1d6d5e1
2017-04-14T14:23:09.316+0200 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
2017-04-14T14:23:09.316+0200 I CONTROL  [initandlisten] allocator: tcmalloc
2017-04-14T14:23:09.316+0200 I CONTROL  [initandlisten] modules: none
2017-04-14T14:23:09.316+0200 I CONTROL  [initandlisten] build environment:
2017-04-14T14:23:09.316+0200 I CONTROL  [initandlisten]     distmod: ubuntu1604
2017-04-14T14:23:09.316+0200 I CONTROL  [initandlisten]     distarch: x86_64
2017-04-14T14:23:09.316+0200 I CONTROL  [initandlisten]     target_arch: x86_64
2017-04-14T14:23:09.316+0200 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log", quiet: true } }
2017-04-14T14:23:09.349+0200 I STORAGE  [initandlisten] 
2017-04-14T14:23:09.349+0200 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-04-14T14:23:09.349+0200 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-04-14T14:23:09.349+0200 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=464M,session_max=20000,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),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-04-14T14:23:09.366+0200 E STORAGE  [initandlisten] WiredTiger error (2) [1492172589:366629][9691:0x7f1755946cc0], file:WiredTiger.wt, connection: /var/lib/mongodb/WiredTiger.wt: handle-open: open: No such file or directory
2017-04-14T14:23:09.367+0200 I -        [initandlisten] Assertion: 28595:2: No such file or directory src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 267
2017-04-14T14:23:09.367+0200 I STORAGE  [initandlisten] exception in initAndListen: 28595 2: No such file or directory, terminating
2017-04-14T14:23:09.367+0200 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2017-04-14T14:23:09.367+0200 I NETWORK  [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2017-04-14T14:23:09.367+0200 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2017-04-14T14:23:09.367+0200 I CONTROL  [initandlisten] now exiting
2017-04-14T14:23:09.367+0200 I CONTROL  [initandlisten] shutting down with code:100

I've looked around and it is not the same error as found here, because that is to do with the fact there isn't an /data/db folder which I have. From that log I can see it is something to do with this line:

2017-04-14T14:23:09.366+0200 E STORAGE  [initandlisten] WiredTiger error (2) [1492172589:366629][9691:0x7f1755946cc0], file:WiredTiger.wt, connection: /var/lib/mongodb/WiredTiger.wt: handle-open: open: No such file or directory

Which is true, when I go to /var/lib/mongodb and do ls -l it results with:

drwxr-xr-x 2 mongodb mongodb 4096 Apr 14 14:10 journal
-rw-r--r-- 1 mongodb mongodb    0 Apr 14 14:02 mongod.lock
-rw-r--r-- 1 mongodb mongodb    0 Apr 14 14:10 WiredTiger
-rw-r--r-- 1 mongodb mongodb   21 Apr 14 14:10 WiredTiger.lock
-rw-r--r-- 1 mongodb mongodb 1004 Apr 14 14:10 WiredTiger.turtle

But I don't know if I should manually create that file as not seen this problem elsewhere. I made sure that mongodb user has permissions on these files too as stated in the answer to this question, but still no luck.

I'm really at a loss as to what to do, any help would be very appreciated as this is my like fifth attempt at getting it working!

Thanks!

Alistair Hughes
  • 387
  • 2
  • 3
  • 13

8 Answers8

16

If you created the mkdir -p /data/db maybe there is a chance that you must start your server with the following command : sudo mongod

macOS/OSX : https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

6

try :

sudo service mongod start ;

then run the mongodb with:

mongo

M.Amer
  • 658
  • 6
  • 13
4

This is a known bug in MongoDB, check the report

Your problem is not that files are missing in general, it's that they go missing when you restart after a clean shutdown. Your problem is not related to the /data/db directory but more to WiredTiger.wt file that is missing after a restart.

Oct 1 20:00:44 alpha mongod.27017[1074]: [initandlisten] WiredTiger (2) [1443729644:306783][1074:0x7fdba8fd4bc0], file:WiredTiger.wt, connection: /data/db/WiredTiger.wt: No such file or directory

The bug report talks about the same thing.

Try:

I would suggest try and disable WiredTiger in the config file.

MongoDB Config Options

WiredTiger

UPDATE: To disable WiredTiger you have to change the storage.engine option in your mongo config file, by default mongod uses WiredTiger but you can also use InMemory LINK

Dusty Boshoff
  • 1,016
  • 14
  • 39
  • 1
    This worked, thanks for bringing the issue to light. I've changed my config like so `engine: mmapv1` under the `storage` section as seen [here](https://gist.github.com/satoryu/495913e59bb249b060cc). Thank you so much for your assistance! – Alistair Hughes Apr 14 '17 at 15:10
  • Where is the config file located? – Luca Guarro Sep 30 '17 at 19:35
  • https://docs.mongodb.com/manual/reference/configuration-options/ - try checking `/etc/mongod.conf` – Dusty Boshoff Oct 01 '17 at 08:40
  • 3
    It would be much better if you can share how to disable `WiredTiger` here, instead of redirecting us to another URL :facepalm: – w3debugger Nov 08 '19 at 18:07
4

Make a directory

sudo mkdir /data/db

Provide access to the directory

sudo chown -R $USER /data/db

Then run

mongod

If you get port already in use the stop mongod, it might be running in the background

sudo service mongod stop

If the last line is

waiting for connections on port 27017

then the mongod is working

Anushil Kumar
  • 674
  • 8
  • 8
1

This command helped me:

mongod --dbpath /data/db --repair
Pang
  • 9,564
  • 146
  • 81
  • 122
Mariana
  • 349
  • 3
  • 18
1

Docker container:

In my case, I was using a docker container running

  mongodb:
    image: 'bitnami/mongodb:latest'
    user: root
    command: "chown -R $USER /bitnami/mongodb"
    volumes:
      - '/var/www/mongodb_data:/bitnami'
    environment:
      - MONGODB_USERNAME=bn_parse
      - MONGODB_PASSWORD=3yfQexfqcc
      - MONGODB_DATABASE=bitnami_parse

I migrated the docker host to other VPS/VM (aws is too expensive).

I added temporarily the command "chown -R $USER /bitnami/mongodb" to change the owner of that folder /bitnami/mongodb. It worked.

ofundefined
  • 2,692
  • 2
  • 18
  • 35
0

for me the 'answer' was to execute the following command (since service mongod start and just mongod failed)

sudo mongod --fork --port 27017 --replSet admin --logpath /data/log/mongo.log

I did not need to turn off wired tiger

user1709076
  • 2,538
  • 9
  • 38
  • 59
0
sudo mdkir data/db

sudo service mongod stop

sudo mongod

mongosh

this fixed it for me on ubuntu 22.04 after hours and hours of hunting down solutions

128KB
  • 398
  • 3
  • 12