Access mongodb through shell

Hi,

I’m trying to access MongoDB through the shell and I’m getting the following error:

ubuntu@ip-xx-x-xx-xxx:~/.local/share/tutor$ tutor local run mongodb bash
docker-compose -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.yml -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.prod.yml -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.tmp.yml --project-name tutor_local run --rm mongodb bash
Starting tutor_local_mongodb-permissions_1 ... done
Creating tutor_local_mongodb_run           ... done
mongodb@77de3e54beb3:/$ mongo
MongoDB shell version v4.2.17
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2022-07-13T00:40:30.591+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:353:17
@(connect):2:6
2022-07-13T00:40:30.593+0000 F  -        [main] exception: connect failed
2022-07-13T00:40:30.593+0000 E  -        [main] exiting with code 1
mongodb@77de3e54beb3:/$ 

I tried to check if the server is running, but I couldn’t find it

ubuntu@ip-xx-x-xx-xxx:~/.local/share/tutor$ systemctl status mongodb.service
Unit mongodb.service could not be found.
ubuntu@ip-xx-x-xx-xxx:~/.local/share/tutor$ service --status-all
 [ + ]  acpid
 [ + ]  apparmor
 [ + ]  apport
 [ + ]  chrony
 [ - ]  console-setup.sh
 [ + ]  cron
 [ - ]  cryptdisks
 [ - ]  cryptdisks-early
 [ + ]  dbus
 [ - ]  grub-common
 [ - ]  hwclock.sh
 [ + ]  irqbalance
 [ - ]  iscsid
 [ - ]  keyboard-setup.sh
 [ + ]  kmod
 [ - ]  lvm2
 [ - ]  lvm2-lvmpolld
 [ + ]  multipath-tools
 [ - ]  open-iscsi
 [ - ]  open-vm-tools
 [ + ]  plymouth
 [ + ]  plymouth-log
 [ + ]  procps
 [ - ]  rsync
 [ - ]  screen-cleanup
 [ + ]  ssh
 [ + ]  ubuntu-fan
 [ + ]  udev
 [ + ]  ufw
 [ + ]  unattended-upgrades
 [ - ]  uuidd
ubuntu@ip-xx-x-xx-xxx:~/.local/share/tutor$ tutor local run mongodb bash
docker-compose -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.yml -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.prod.yml -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.tmp.yml --project-name tutor_local run --rm mongodb bash
Starting tutor_local_mongodb-permissions_1 ... done
Creating tutor_local_mongodb_run           ... done
mongodb@27ac804dd3ae:/$ service --status-all
 [ ? ]  hwclock.sh
 [ - ]  procps
mongodb@27ac804dd3ae:/$ 

Can anyone help me with this? Thanks!

I usually just connect to the running mongodb instance using:

docker exec -it tutor_local_mongodb_1 bash

Then running:

root@a6ba0acf0597:/# mongo
MongoDB shell version v4.0.25
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("0bded2dc-e58c-4465-b4df-c6ac80d292ac") }
MongoDB server version: 4.0.25
Server has startup warnings: 
...
> use openedx
switched to db openedx
>