M103 Chapter 1 Lab 1

For lab 1, I am having issues connecting to mongod.
I have ran the following:
vagrant@m103:~$ mongod --port 27000 --dbpath /data/db --auth --bind_ip 192.168.103.100,127.0.0.1

However, I get the following:
2019-10-16T18:38:17.217+0000 I CONTROL [initandlisten] MongoDB starting : pid=11483 port=27000 dbpath=/data/db 64-bit host=m103
2019-10-16T18:38:17.218+0000 I CONTROL [initandlisten] db version v3.6.14
2019-10-16T18:38:17.218+0000 I CONTROL [initandlisten] git version: cbef87692475857c7ee6e764c8f5104b39c342a1
2019-10-16T18:38:17.219+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2019-10-16T18:38:17.219+0000 I CONTROL [initandlisten] allocator: tcmalloc
2019-10-16T18:38:17.219+0000 I CONTROL [initandlisten] modules: enterprise
2019-10-16T18:38:17.219+0000 I CONTROL [initandlisten] build environment:
2019-10-16T18:38:17.219+0000 I CONTROL [initandlisten] distmod: ubuntu1404
2019-10-16T18:38:17.219+0000 I CONTROL [initandlisten] distarch: x86_64
2019-10-16T18:38:17.219+0000 I CONTROL [initandlisten] target_arch: x86_64
2019-10-16T18:38:17.219+0000 I CONTROL [initandlisten] options: { net: { bindIp: “192.168.103.100,127.0.0.1”, port: 27000 }, security: { authorization: “enabled” }, storage: { dbPath: “/data/db” } }
2019-10-16T18:38:17.220+0000 I STORAGE [initandlisten] exception in initAndListen: DBPathInUse: Unable to lock the lock file: /data/db/mongod.lock (Resource temporarily unavailable). Another mongod instance is already running on the /data/db directory, terminating
2019-10-16T18:38:17.220+0000 I CONTROL [initandlisten] now exiting
2019-10-16T18:38:17.220+0000 I CONTROL [initandlisten] shutting down with code:100

As a result when I run mongo command it fails to connect, so I can’t setup the user. Have been trying to get this to run for the last few hours. Any ideas where I am going wrong?

Hey @Conor_34734, I’ve highlighted the culprit. Shout if you need further assistance.

@007_jb tried restarting and running the code again and get the following:

vagrant@m103:~$ mongod --port 27000 --dbpath /data/db --auth --bind_ip 192.168.103.100,127.0.0.1
2019-10-16T19:06:12.560+0000 I CONTROL [initandlisten] MongoDB starting : pid=11894 port=27000 dbpath=/data/db 64-bit host=m103
2019-10-16T19:06:12.560+0000 I CONTROL [initandlisten] db version v3.6.14
2019-10-16T19:06:12.560+0000 I CONTROL [initandlisten] git version: cbef87692475857c7ee6e764c8f5104b39c342a1
2019-10-16T19:06:12.560+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2019-10-16T19:06:12.560+0000 I CONTROL [initandlisten] allocator: tcmalloc
2019-10-16T19:06:12.560+0000 I CONTROL [initandlisten] modules: enterprise
2019-10-16T19:06:12.560+0000 I CONTROL [initandlisten] build environment:
2019-10-16T19:06:12.561+0000 I CONTROL [initandlisten] distmod: ubuntu1404
2019-10-16T19:06:12.561+0000 I CONTROL [initandlisten] distarch: x86_64
2019-10-16T19:06:12.561+0000 I CONTROL [initandlisten] target_arch: x86_64
2019-10-16T19:06:12.561+0000 I CONTROL [initandlisten] options: { net: { bindIp: “192.168.103.100,127.0.0.1”, port: 27000 }, security: { authorization: “enabled” }, storage: { dbPath: “/data/db” } }
2019-10-16T19:06:12.562+0000 I - [initandlisten] Detected data files in /data/db created by the ‘wiredTiger’ storage engine, so setting the active storage engine to ‘wiredTiger’.
2019-10-16T19:06:12.562+0000 I STORAGE [initandlisten]
2019-10-16T19:06:12.562+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-10-16T19:06:12.563+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-10-16T19:06:12.563+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=488M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),compatibility=(release=“3.0”,require_max=“3.0”),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2019-10-16T19:06:13.959+0000 E STORAGE [initandlisten] WiredTiger error (13) [1571252773:959538][11894:0x7f489ea82ac0], wiredtiger_open: __posix_open_file, 715: /data/db/WiredTiger.turtle: handle-open: open: Permission denied
2019-10-16T19:06:13.959+0000 E - [initandlisten] Assertion: 28595:13: Permission denied src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 486
2019-10-16T19:06:13.960+0000 I STORAGE [initandlisten] exception in initAndListen: Location28595: 13: Permission denied, terminating
2019-10-16T19:06:13.960+0000 I NETWORK [initandlisten] shutdown: going to close listening sockets…
2019-10-16T19:06:13.960+0000 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27000.sock
2019-10-16T19:06:13.960+0000 I CONTROL [initandlisten] now exiting
2019-10-16T19:06:13.961+0000 I CONTROL [initandlisten] shutting down with code:100

If I recall, there’s somewhere in the lectures where it mentions changing the folder permissions for the /data/db directory. Check what permissions you have for this folder.

I’ve checked back through the videos so far and can’t see anything on permissions for /data/db. I know for dbpath in the lecture video he first had to mkdir - tried this for /data/db but was told the file already exists.
Then there is the code given in the lab for creating a user, but I need to have connected to mongod in order to run that.

Tried icacls /data/db to see permissions for the folder but the command isn’t found. How else can I check the permissions?

Sorry if all of this is wrecking your head. Just really struggling with it all at the moment. Yourhelp is really appreciated.

Don’t worry! I’ll help as much as I can :v::slight_smile:

When you said you started again, how exactly did you do that?

Also, run the following Linux command and show me a screenshot of the results:
ps -ef | grep "[m]ongo"

Cheers.

Tried a few commands off stack overflow to try stop the original mongod process that was running: sudo killall & sudo service mongod stop . Then exited vagrant and restarted it.
Also tried closing and reopening a new cmd promt window and running the lot again and still get the same error.

I’m on windows so that linux command doesn’t seem to return anything? ran ps -edaf | grep mongo and got:

vagrant 12401 12380 0 20:02 pts/0 00:00:00 grep --color=auto mongo

If for any reason you want to kill a single process, use kill -9 <process id>. And to find the process id, you’ll use the ps command I gave you.

You’re in a Ubuntu (Linux) virtual machine so the initial command was fine. No output means no processes are running. The one-line output you got from the second ps command that you ran is showing you the grep command which spawns a process, that’s why I use [m]ongo to suppress that line because it’s irrelevant.

Let’s see what the user permissions are for the /data/db directory.

Ok, will do that in future thanks.

How do I check user permissions?

Here:
ls -l /data/db

vagrant@m103:~$ ls -l /data/db
total 404
-rw------- 1 vagrant vagrant 45 Oct 15 21:09 WiredTiger
-rw------- 1 vagrant vagrant 21 Oct 15 21:09 WiredTiger.lock
-rw------- 1 root root 1107 Oct 16 19:03 WiredTiger.turtle
-rw------- 1 vagrant vagrant 69632 Oct 16 19:03 WiredTiger.wt
-rw------- 1 root root 4096 Oct 16 19:03 WiredTigerLAS.wt
-rw------- 1 vagrant vagrant 36864 Oct 16 19:03 _mdb_catalog.wt
-rw------- 1 vagrant vagrant 32768 Oct 16 19:03 collection-0–1128430364534344976.wt
-rw------- 1 vagrant vagrant 16384 Oct 16 19:03 collection-0–4456662190085857726.wt
-rw------- 1 vagrant vagrant 36864 Oct 16 19:03 collection-2–1128430364534344976.wt
-rw------- 1 vagrant vagrant 20480 Oct 16 19:03 collection-4–1128430364534344976.wt
drwx------ 2 vagrant vagrant 4096 Oct 16 19:03 diagnostic.data
-rw------- 1 vagrant vagrant 16384 Oct 16 18:12 index-0–767059538198336484.wt
-rw------- 1 vagrant vagrant 16384 Oct 16 18:12 index-1–767059538198336484.wt
-rw------- 1 vagrant vagrant 16384 Oct 16 19:03 index-2–767059538198336484.wt
-rw------- 1 vagrant vagrant 4096 Oct 16 18:12 index-3–767059538198336484.wt
-rw------- 1 vagrant vagrant 4096 Oct 16 19:00 index-4–767059538198336484.wt
-rw------- 1 vagrant vagrant 36864 Oct 16 19:03 index-5–767059538198336484.wt
drwx------ 2 vagrant vagrant 4096 Oct 16 19:03 journal
-rw------- 1 vagrant vagrant 1543 Oct 16 18:22 log.log
-rw------- 1 vagrant vagrant 4126 Oct 16 19:00 log.log.2019-10-16T18-14-25
-rw------- 1 root root 1518 Oct 16 18:14 log.log.2019-10-16T18-19-21
-rw------- 1 root root 1518 Oct 16 18:19 log.log.2019-10-16T18-19-28
-rw------- 1 vagrant vagrant 1543 Oct 16 18:19 log.log.2019-10-16T18-21-10
-rw------- 1 root root 1518 Oct 16 18:21 log.log.2019-10-16T18-21-22
-rw------- 1 vagrant vagrant 1543 Oct 16 18:21 log.log.2019-10-16T18-21-32
-rw------- 1 vagrant vagrant 1543 Oct 16 18:21 log.log.2019-10-16T18-22-39
-rw------- 1 vagrant vagrant 0 Oct 16 19:03 mongod.lock
-rw------- 1 vagrant vagrant 36864 Oct 16 19:03 sizeStorer.wt
-rw------- 1 vagrant vagrant 114 Oct 15 21:09 storage.bson

There’s quite a lot of files in there. It’s either you delete all the files in that directory or create the mongod in another directory (i.e. create a new folder and repoint --dbpath to the new path).

I setup a new dir /data/db2
This seemed to work and I was able to run mongo in another window.
I exited mongo and then tried to run the validation code:

validate_lab_launch_mongod

I got the error:

You need to specify db path /data/db.

How do I change this to the new path I setup so I can get the validation key?

Good! Open the validator file in Notepad++ and have a look in there.

I think it’ll be easier if you just delete all files in /data/db instead of trying to find and tinker with the validator file:
rm -r /data/db

HI @Conor_34734,

You are seeing this error as our validation script requires that you pass “/data/db” as your dbpath. The script fails if any one of the criteria mentioned in our lab notes is not followed.

If you want to run the validation script successfully, you’ll have to follow all the exact instructions and in this case, use “/data/db” as your dbpath.

Please copy all the current files at this location to a new location (say “/data/backup”) and empty this directory.
After doing the above, please try running your process again, it should work.

Let me know if you still face any issues.

Thanks,
Muskan
Curriculum Support Engineer

Hi @Muskan_Sharma @007_jb

I tried to remove everything from the directory and rerun my code but getting the following:

vagrant@m103:~$ rm -r /data/db/

rm: remove write-protected regular file ‘/data/db/journal/WiredTigerLog.0000000016’?
rm: remove write-protected regular file ‘/data/db/journal/WiredTigerPreplog.0000000002’?
rm: remove write-protected regular file ‘/data/db/journal/WiredTigerPreplog.0000000001’?
rm: cannot remove ‘/data/db/journal’: Directory not empty
rm: remove write-protected regular file ‘/data/db/WiredTiger.turtle’?
rm: remove write-protected regular file ‘/data/db/log.log.2019-10-16T18-19-28’?
rm: remove write-protected regular file ‘/data/db/WiredTigerLAS.wt’?
rm: remove write-protected regular file ‘/data/db/log.log.2019-10-16T18-21-22’?
rm: remove write-protected regular file ‘/data/db/diagnostic.data/metrics.2019-10-16T19-02-24Z-00000’?
rm: remove write-protected regular file ‘/data/db/diagnostic.data/metrics.2019-10-16T19-03-02Z-00000’?
rm: cannot remove ‘/data/db/diagnostic.data’: Directory not empty
rm: remove write-protected regular file ‘/data/db/log.log.2019-10-16T18-19-21’?

I clicked Enter after each one of those.

Then checked the directory and got this:

vagrant@m103:~$ ls -l /data/db

total 28
-rw------- 1 root root 1107 Oct 16 19:03 WiredTiger.turtle
-rw------- 1 root root 4096 Oct 16 19:03 WiredTigerLAS.wt
drwx------ 2 vagrant vagrant 4096 Oct 17 19:43 diagnostic.data
drwx------ 2 vagrant vagrant 4096 Oct 16 19:03 journal
-rw------- 1 root root 1518 Oct 16 18:14 log.log.2019-10-16T18-19-21
-rw------- 1 root root 1518 Oct 16 18:19 log.log.2019-10-16T18-19-28
-rw------- 1 root root 1518 Oct 16 18:21 log.log.2019-10-16T18-21-22

Ran my code again to try connect to mongod but it is still not working:

vagrant@m103:~$ mongod --port 27000 --dbpath /data/db --auth --bind_ip 192.168.103.100,127.0.0.1

2019-10-17T19:51:56.005+0000 I CONTROL [initandlisten] MongoDB starting : pid=13990 port=27000 dbpath=/data/db 64-bit host=m103
2019-10-17T19:51:56.005+0000 I CONTROL [initandlisten] db version v3.6.14
2019-10-17T19:51:56.005+0000 I CONTROL [initandlisten] git version: cbef87692475857c7ee6e764c8f5104b39c342a1
2019-10-17T19:51:56.005+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2019-10-17T19:51:56.005+0000 I CONTROL [initandlisten] allocator: tcmalloc
2019-10-17T19:51:56.005+0000 I CONTROL [initandlisten] modules: enterprise
2019-10-17T19:51:56.005+0000 I CONTROL [initandlisten] build environment:
2019-10-17T19:51:56.005+0000 I CONTROL [initandlisten] distmod: ubuntu1404
2019-10-17T19:51:56.005+0000 I CONTROL [initandlisten] distarch: x86_64
2019-10-17T19:51:56.005+0000 I CONTROL [initandlisten] target_arch: x86_64
2019-10-17T19:51:56.005+0000 I CONTROL [initandlisten] options: { net: { bindIp: “192.168.103.100,127.0.0.1”, port: 27000 }, security: { authorization: “enabled” }, storage: { dbPath: “/data/db” } }
2019-10-17T19:51:56.005+0000 I STORAGE [initandlisten]
2019-10-17T19:51:56.005+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-10-17T19:51:56.005+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-10-17T19:51:56.006+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=488M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),compatibility=(release=“3.0”,require_max=“3.0”),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2019-10-17T19:51:56.463+0000 E STORAGE [initandlisten] WiredTiger error (13) [1571341916:463316][13990:0x7f53fbd87ac0], wiredtiger_open: __posix_open_file, 715: /data/db/WiredTiger.turtle: handle-open: open: Permission denied
2019-10-17T19:51:56.463+0000 E - [initandlisten] Assertion: 28595:13: Permission denied src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 486
2019-10-17T19:51:56.463+0000 I STORAGE [initandlisten] exception in initAndListen: Location28595: 13: Permission denied, terminating
2019-10-17T19:51:56.463+0000 I NETWORK [initandlisten] shutdown: going to close listening sockets…
2019-10-17T19:51:56.463+0000 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27000.sock
2019-10-17T19:51:56.463+0000 I CONTROL [initandlisten] now exiting
2019-10-17T19:51:56.463+0000 I CONTROL [initandlisten] shutting down with code:100

@007_jb @Muskan_Sharma
just realised I had to click Y and enter when removing the files. Redid it and i was able to get it to run.

Thanks for yere help on this

1 Like

Hi @Conor_34734,

Good to hear that you were able to figure it out!

Please feel free to reach out to us in case of any other issues.

Thanks,
Muskan
Curriculum Support Engineer

I think i have a problem too with the lab now , i have the below command
vagrant@m103:~$ mongod --port 27000 --dbpath /data/db --auth --bind_ip 192.168.103.100,127.0.0.1

and it just says … waiting for connections on port 27000