Login into MongoDB - juju/juju GitHub Wiki

Script (Juju 2.0 only)

The following script will SSH to a Juju 2.0 controller machine and start a mongo shell. It optionally takes the machine to connect to and the model name (defaulting to machine "0" in the model named "controller"). Use juju switch first to ensure the desired controller is selected.

#!/bin/bash

machine=${1:-0}
model=${2:-controller}

read -d '' -r cmds <<'EOF'
conf=/var/lib/juju/agents/machine-*/agent.conf
user=`sudo grep tag $conf | cut -d' ' -f2`
password=`sudo grep statepassword $conf | cut -d' ' -f2`
/usr/lib/juju/mongo*/bin/mongo 127.0.0.1:37017/juju --authenticationDatabase admin --ssl --sslAllowInvalidCertificates --username "$user" --password "$password"
EOF

juju ssh -m $model $machine "$cmds"

Manually

Get the MongoDB password by running:

$ sudo grep statepassword /var/lib/juju/agents/machine-*/agent.conf | cut -d' ' -f2

On xenial, juju-mongodb3.2 should include the mongo client, so run it from its installed directory:

/usr/lib/juju/mongo3.2/bin/mongo 127.0.0.1:37017/juju -u "machine-0" -p "<password>" --sslAllowInvalidCertificates --ssl --authenticationDatabase admin

For older Juju versions where MongoDB 2 is in use, install mongodb-clients:

sudo apt-get install mongodb-clients

Then log in to the shell like this:

mongo 127.0.0.1:37017/juju --authenticationDatabase admin --ssl --username admin --password "<password>"

For Juju 1.x

Use oldpassword instead of statepassword in scripts and commands above.

⚠️ **GitHub.com Fallback** ⚠️