Failed to connect to 127.0.0.1:27017 (homework 1.1)

vagrant@database:~ mongod 2019-12-07T01:47:41.547+0000 I CONTROL [initandlisten] MongoDB starting : pid=10681 port=27017 dbpath=/data/db 64-bit host=database 2019-12-07T01:47:41.547+0000 I CONTROL [initandlisten] db version v3.2.22 2019-12-07T01:47:41.548+0000 I CONTROL [initandlisten] git version: 105acca0d443f9a47c1a5bd608fd7133840a58dd 2019-12-07T01:47:41.548+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014 2019-12-07T01:47:41.549+0000 I CONTROL [initandlisten] allocator: tcmalloc 2019-12-07T01:47:41.549+0000 I CONTROL [initandlisten] modules: enterprise 2019-12-07T01:47:41.549+0000 I CONTROL [initandlisten] build environment: 2019-12-07T01:47:41.550+0000 I CONTROL [initandlisten] distmod: ubuntu1404 2019-12-07T01:47:41.550+0000 I CONTROL [initandlisten] distarch: x86_64 2019-12-07T01:47:41.550+0000 I CONTROL [initandlisten] target_arch: x86_64 2019-12-07T01:47:41.551+0000 I CONTROL [initandlisten] options: {} 2019-12-07T01:47:41.571+0000 I STORAGE [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating 2019-12-07T01:47:41.571+0000 I CONTROL [initandlisten] dbexit: rc: 100 vagrant@database:~ mongo
MongoDB shell version: 3.2.22
connecting to: test
2019-12-07T01:47:47.586+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
2019-12-07T01:47:47.587+0000 E QUERY [thread1] Error: couldn’t connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14
@(connect):1:6

exception: connect failed
vagrant@database:~$ mongo admin
MongoDB shell version: 3.2.22
connecting to: admin
2019-12-07T01:47:57.108+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
2019-12-07T01:47:57.108+0000 E QUERY [thread1] Error: couldn’t connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14
@(connect):1:6

exception: connect failed
vagrant@database:~$

Here’s the culprit.

You also need to ensure that mongod was successfully started before running mongo.

vagrant@database:~ mongod 2019-12-07T02:06:37.950+0000 I CONTROL [initandlisten] MongoDB starting : pid=8219 port=27017 dbpath=/data/db 64-bit host=database 2019-12-07T02:06:37.951+0000 I CONTROL [initandlisten] db version v3.2.22 2019-12-07T02:06:37.951+0000 I CONTROL [initandlisten] git version: 105acca0d443f9a47c1a5bd608fd7133840a58dd 2019-12-07T02:06:37.952+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014 2019-12-07T02:06:37.952+0000 I CONTROL [initandlisten] allocator: tcmalloc 2019-12-07T02:06:37.952+0000 I CONTROL [initandlisten] modules: enterprise 2019-12-07T02:06:37.952+0000 I CONTROL [initandlisten] build environment: 2019-12-07T02:06:37.953+0000 I CONTROL [initandlisten] distmod: ubuntu1404 2019-12-07T02:06:37.953+0000 I CONTROL [initandlisten] distarch: x86_64 2019-12-07T02:06:37.953+0000 I CONTROL [initandlisten] target_arch: x86_64 2019-12-07T02:06:37.954+0000 I CONTROL [initandlisten] options: {} 2019-12-07T02:06:37.972+0000 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating 2019-12-07T02:06:37.973+0000 I CONTROL [initandlisten] dbexit: rc: 100 vagrant@database:~

vagrant@database:~$ sudo chown -R mongod:mongod /data/db

chown: invalid user: ‘mongod:mongod’

vagrant@database:~$

It’s supposed to be vagrant:vagrant