M103 chapter 2 lab built-in roles

the lab question asks:

  1. Connect to a mongod instance that is already running in the background on port 27000 . You can find the options used to launch mongod in the configuration file in your file editor.The m103-admin user has also already been created for you with password m103-pass.

but when i issue:

mongo --username m103-admin --password m103-pass

i get this error:

2022-01-15T14:03:06.037+0000 E QUERY    [js] 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:328:13
@(connect):1:6
exception: connect failed

If you see the error message it is trying to connect to mongod on port 27017 (default port)

Pass correct port_num to your command

but in the question it says

Connect to a mongod instance that is already running in the background on port 27000

also the configuration file is:

storage:
  dbPath: /var/mongodb/db
net:
  bindIp: localhost
  port: 27000
security:
  authorization: enabled
systemLog:
  destination: file
  path: /var/mongodb/logs/mongod.log
  logAppend: true
processManagement:
  fork: true

also i can not re run mongod with:

mongod -f mongod.conf

because i get this error:

about to fork child process, waiting until server is ready for connections.
forked process: 368
ERROR: child process failed, exited with error number 48
To see additional information in this output, start without the "--fork" option.

That is correct
You have to connect to mongod running on port 27000

Did you try as i suggested giving port 27000?

mongo -u xyz -p xyz -port 27000

When you issue mongo command without giving the port number it will try to connect to default mongod which runs on port 27017
Since it is not running on 27017 your connect is failing
Try as i shown above.No need to start mongod again with config file as you are trying

2 Likes