Skip to content

Commit

Permalink
Update documentation to mongosh
Browse files Browse the repository at this point in the history
  • Loading branch information
phvalguima committed Sep 21, 2023
1 parent 89700eb commit 2482871
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 67 deletions.
12 changes: 6 additions & 6 deletions docs/tutorial/t-deploy-mongodb.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is part of the [Charmed MongoDB Tutorial](/t/charmed-mongodb-tutorial/8061)

To deploy Charmed MongoDB, all you need to do is run the following command, which will fetch the charm from [Charmhub](https://charmhub.io/mongodb?channel=5/edge) and deploy it to your model:
```shell
juju deploy mongodb --channel 5/edge
juju deploy mongodb --channel 6/edge
```

Juju will now fetch Charmed MongoDB and begin deploying it to the LXD cloud. This process can take several minutes depending on how provisioned (RAM, CPU,etc) your machine is. You can track the progress by running:
Expand All @@ -33,7 +33,7 @@ To exit the screen with `juju status --watch 1s`, enter `Ctrl+c`.
## Access MongoDB
> **!** *Disclaimer: this part of the tutorial accesses MongoDB via the `admin` user. **Do not** directly interface with the admin user in a production environment. In a production environment [always create a separate user](https://www.mongodb.com/docs/manual/tutorial/create-users/) and connect to MongoDB with that user instead. Later in the section covering Relations we will cover how to access MongoDB without the admin user.*
The first action most users take after installing MongoDB is accessing MongoDB. The easiest way to do this is via the MongoDB shell, with `mongo`. You can read more about the MongoDB shell [here](https://www.mongodb.com/docs/mongodb-shell/). For this part of the Tutorial we will access MongoDB via `mongo`. Fortunately there is no need to install the Mongo shell, as `mongo` is already installed on the units hosting the Charmed MongoDB application as `charmed-mongodb.mongo`.
The first action most users take after installing MongoDB is accessing MongoDB. The easiest way to do this is via the MongoDB shell, with `mongosh`. You can read more about the MongoDB shell [here](https://www.mongodb.com/docs/mongodb-shell/). For this part of the Tutorial we will access MongoDB via `mongosh`. Fortunately there is no need to install the Mongo shell, as `mongosj` is already installed on the units hosting the Charmed MongoDB application as `charmed-mongodb.mongosh`.

### MongoDB URI
Connecting to the database requires a Uniform Resource Identifier (URI), MongoDB expects a [MongoDB specific URI](https://www.mongodb.com/docs/manual/reference/connection-string/). The URI for MongoDB contains information which is used to authenticate us to the database. We use a URI of the format:
Expand Down Expand Up @@ -101,7 +101,7 @@ export REPL_SET_NAME="mongodb"
```

### Generate the MongoDB URI
Now that we have the necessary fields to connect to the URI, we can connect to MongoDB with `charmed-mongodb.mongo` via the URI. We can create the URI with:
Now that we have the necessary fields to connect to the URI, we can connect to MongoDB with `charmed-mongodb.mongosh` via the URI. We can create the URI with:
```shell
export URI=mongodb://$DB_USERNAME:$DB_PASSWORD@$HOST_IP/$DB_NAME?replicaSet=$REPL_SET_NAME
```
Expand All @@ -111,16 +111,16 @@ echo $URI
```

### Connect via MongoDB URI
As said earlier, `mongo` is already installed in Charmed MongoDB as `charmed-mongodb.mongo`. To access the unit hosting Charmed MongoDB, ssh into it:
As said earlier, `mongosh` is already installed in Charmed MongoDB as `charmed-mongodb.mongosh`. To access the unit hosting Charmed MongoDB, ssh into it:
```shell
juju ssh mongodb/0
```
*Note if at any point you'd like to leave the unit hosting Charmed MongoDB, enter* `exit`.

While `ssh`d into `mongodb/0`, we can access `mongo`, using the URI that we saved in the step [Generate the MongoDB URI](#generate-the-mongodb-uri).
While `ssh`d into `mongodb/0`, we can access `mongosh`, using the URI that we saved in the step [Generate the MongoDB URI](#generate-the-mongodb-uri).

```shell
charmed-mongodb.mongo <saved URI>
charmed-mongodb.mongosh <saved URI>
```

You should now see:
Expand Down
119 changes: 60 additions & 59 deletions docs/tutorial/t-managing-units.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Machine State Address Inst id Series AZ Message
2 started 10.23.62.243 juju-d35d30-2 jammy Running
```

You can trust that Charmed MongoDB added these replicas correctly. But if you wanted to verify the replicas got added correctly you could connect to MongoDB via `charmed-mongodb.mongo`. Since your replica set has 2 additional hosts you will need to update the hosts in your URI. You can retrieve these host IPs with:
You can trust that Charmed MongoDB added these replicas correctly. But if you wanted to verify the replicas got added correctly you could connect to MongoDB via `charmed-mongodb.mongosh`. Since your replica set has 2 additional hosts you will need to update the hosts in your URI. You can retrieve these host IPs with:
```shell
export HOST_IP_1=$(juju run --unit mongodb/1 -- hostname -I | xargs)
export HOST_IP_2=$(juju run --unit mongodb/2 -- hostname -I | xargs)
Expand All @@ -50,23 +50,23 @@ Now view and save the output of the URI:
echo $URI
```

Like earlier we access `mongo` by `ssh`ing into one of the Charmed MongoDB hosts:
Like earlier we access `mongosh` by `ssh`ing into one of the Charmed MongoDB hosts:
```shell
juju ssh mongodb/0
```

While `ssh`d into `mongodb/0`, we can access `mongo` with `charmed-mongodb.mongo`, using our new URI that we saved above.
While `ssh`d into `mongodb/0`, we can access `mongosh` with `charmed-mongodb.mongosh`, using our new URI that we saved above.
```shell
charmed-mongodb.mongo <saved URI>
charmed-mongodb.mongosh <saved URI>
```

Now type `rs.status()` and you should see your replica set configuration. It should look something like this:
```json
{
set: 'mongodb',
date: ISODate("2022-12-02T14:39:52.732Z"),
date: ISODate("2023-09-21T10:19:56.666Z"),
myState: 1,
term: Long("1"),
term: Long("8"),
syncSourceHost: '',
syncSourceId: -1,
heartbeatIntervalMillis: Long("2000"),
Expand All @@ -75,105 +75,106 @@ Now type `rs.status()` and you should see your replica set configuration. It sho
votingMembersCount: 3,
writableVotingMembersCount: 3,
optimes: {
lastCommittedOpTime: { ts: Timestamp({ t: 1669991990, i: 1 }), t: Long("1") },
lastCommittedWallTime: ISODate("2022-12-02T14:39:50.020Z"),
readConcernMajorityOpTime: { ts: Timestamp({ t: 1669991990, i: 1 }), t: Long("1") },
appliedOpTime: { ts: Timestamp({ t: 1669991990, i: 1 }), t: Long("1") },
durableOpTime: { ts: Timestamp({ t: 1669991990, i: 1 }), t: Long("1") },
lastAppliedWallTime: ISODate("2022-12-02T14:39:50.020Z"),
lastDurableWallTime: ISODate("2022-12-02T14:39:50.020Z")
lastCommittedOpTime: { ts: Timestamp({ t: 1695291593, i: 4 }), t: Long("8") },
lastCommittedWallTime: ISODate("2023-09-21T10:19:53.387Z"),
readConcernMajorityOpTime: { ts: Timestamp({ t: 1695291593, i: 4 }), t: Long("8") },
appliedOpTime: { ts: Timestamp({ t: 1695291593, i: 4 }), t: Long("8") },
durableOpTime: { ts: Timestamp({ t: 1695291593, i: 4 }), t: Long("8") },
lastAppliedWallTime: ISODate("2023-09-21T10:19:53.387Z"),
lastDurableWallTime: ISODate("2023-09-21T10:19:53.387Z")
},
lastStableRecoveryTimestamp: Timestamp({ t: 1669991950, i: 1 }),
lastStableRecoveryTimestamp: Timestamp({ t: 1695291546, i: 2 }),
electionCandidateMetrics: {
lastElectionReason: 'electionTimeout',
lastElectionDate: ISODate("2022-12-02T11:24:09.587Z"),
electionTerm: Long("1"),
lastCommittedOpTimeAtElection: { ts: Timestamp({ t: 1669980249, i: 1 }), t: Long("-1") },
lastSeenOpTimeAtElection: { ts: Timestamp({ t: 1669980249, i: 1 }), t: Long("-1") },
numVotesNeeded: 1,
lastElectionDate: ISODate("2023-09-21T09:57:28.251Z"),
electionTerm: Long("8"),
lastCommittedOpTimeAtElection: { ts: Timestamp({ t: 0, i: 0 }), t: Long("-1") },
lastSeenOpTimeAtElection: { ts: Timestamp({ t: 1695290223, i: 4 }), t: Long("7") },
numVotesNeeded: 2,
priorityAtElection: 1,
electionTimeoutMillis: Long("10000"),
newTermStartDate: ISODate("2022-12-02T11:24:09.630Z"),
wMajorityWriteAvailabilityDate: ISODate("2022-12-02T11:24:09.651Z")
numCatchUpOps: Long("0"),
newTermStartDate: ISODate("2023-09-21T09:57:28.258Z"),
wMajorityWriteAvailabilityDate: ISODate("2023-09-21T09:57:28.810Z")
},
members: [
{
_id: 0,
name: '10.23.62.156:27017',
name: '10.165.186.135:27017',
health: 1,
state: 1,
stateStr: 'PRIMARY',
uptime: 11747,
optime: { ts: Timestamp({ t: 1669991990, i: 1 }), t: Long("1") },
optimeDate: ISODate("2022-12-02T14:39:50.000Z"),
lastAppliedWallTime: ISODate("2022-12-02T14:39:50.020Z"),
lastDurableWallTime: ISODate("2022-12-02T14:39:50.020Z"),
uptime: 1371,
optime: { ts: Timestamp({ t: 1695291593, i: 4 }), t: Long("8") },
optimeDate: ISODate("2023-09-21T10:19:53.000Z"),
lastAppliedWallTime: ISODate("2023-09-21T10:19:53.387Z"),
lastDurableWallTime: ISODate("2023-09-21T10:19:53.387Z"),
syncSourceHost: '',
syncSourceId: -1,
infoMessage: '',
electionTime: Timestamp({ t: 1669980249, i: 2 }),
electionDate: ISODate("2022-12-02T11:24:09.000Z"),
electionTime: Timestamp({ t: 1695290248, i: 1 }),
electionDate: ISODate("2023-09-21T09:57:28.000Z"),
configVersion: 5,
configTerm: 1,
configTerm: 8,
self: true,
lastHeartbeatMessage: ''
},
{
_id: 1,
name: '10.23.62.55:27017',
name: '10.165.186.225:27017',
health: 1,
state: 2,
stateStr: 'SECONDARY',
uptime: 305,
optime: { ts: Timestamp({ t: 1669991990, i: 1 }), t: Long("1") },
optimeDurable: { ts: Timestamp({ t: 1669991990, i: 1 }), t: Long("1") },
optimeDate: ISODate("2022-12-02T14:39:50.000Z"),
optimeDurableDate: ISODate("2022-12-02T14:39:50.000Z"),
lastAppliedWallTime: ISODate("2022-12-02T14:39:50.020Z"),
lastDurableWallTime: ISODate("2022-12-02T14:39:50.020Z"),
lastHeartbeat: ISODate("2022-12-02T14:39:51.868Z"),
lastHeartbeatRecv: ISODate("2022-12-02T14:39:51.882Z"),
uptime: 1351,
optime: { ts: Timestamp({ t: 1695291593, i: 4 }), t: Long("8") },
optimeDurable: { ts: Timestamp({ t: 1695291593, i: 4 }), t: Long("8") },
optimeDate: ISODate("2023-09-21T10:19:53.000Z"),
optimeDurableDate: ISODate("2023-09-21T10:19:53.000Z"),
lastAppliedWallTime: ISODate("2023-09-21T10:19:53.387Z"),
lastDurableWallTime: ISODate("2023-09-21T10:19:53.387Z"),
lastHeartbeat: ISODate("2023-09-21T10:19:56.298Z"),
lastHeartbeatRecv: ISODate("2023-09-21T10:19:55.325Z"),
pingMs: Long("0"),
lastHeartbeatMessage: '',
syncSourceHost: '10.23.62.156:27017',
syncSourceHost: '10.165.186.135:27017',
syncSourceId: 0,
infoMessage: '',
configVersion: 5,
configTerm: 1
configTerm: 8
},
{
_id: 2,
name: '10.23.62.243:27017',
name: '10.165.186.179:27017',
health: 1,
state: 2,
stateStr: 'SECONDARY',
uptime: 300,
optime: { ts: Timestamp({ t: 1669991990, i: 1 }), t: Long("1") },
optimeDurable: { ts: Timestamp({ t: 1669991990, i: 1 }), t: Long("1") },
optimeDate: ISODate("2022-12-02T14:39:50.000Z"),
optimeDurableDate: ISODate("2022-12-02T14:39:50.000Z"),
lastAppliedWallTime: ISODate("2022-12-02T14:39:50.020Z"),
lastDurableWallTime: ISODate("2022-12-02T14:39:50.020Z"),
lastHeartbeat: ISODate("2022-12-02T14:39:51.861Z"),
lastHeartbeatRecv: ISODate("2022-12-02T14:39:52.372Z"),
uptime: 1351,
optime: { ts: Timestamp({ t: 1695291593, i: 4 }), t: Long("8") },
optimeDurable: { ts: Timestamp({ t: 1695291593, i: 4 }), t: Long("8") },
optimeDate: ISODate("2023-09-21T10:19:53.000Z"),
optimeDurableDate: ISODate("2023-09-21T10:19:53.000Z"),
lastAppliedWallTime: ISODate("2023-09-21T10:19:53.387Z"),
lastDurableWallTime: ISODate("2023-09-21T10:19:53.387Z"),
lastHeartbeat: ISODate("2023-09-21T10:19:56.602Z"),
lastHeartbeatRecv: ISODate("2023-09-21T10:19:55.344Z"),
pingMs: Long("0"),
lastHeartbeatMessage: '',
syncSourceHost: '10.23.62.55:27017',
syncSourceId: 1,
syncSourceHost: '10.165.186.135:27017',
syncSourceId: 0,
infoMessage: '',
configVersion: 5,
configTerm: 1
configTerm: 8
}
],
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1669991990, i: 1 }),
clusterTime: Timestamp({ t: 1695291593, i: 4 }),
signature: {
hash: Binary(Buffer.from("dbe96e73cf659617bb88b6ad11152551c0dd9c8d", "hex"), 0),
keyId: Long("7172510554420936709")
hash: Binary.createFromBase64("HiSmynKsjpsdvfJFZemY8q75KVs=", 0),
keyId: Long("7281212693464219655")
}
},
operationTime: Timestamp({ t: 1669991990, i: 1 })
operationTime: Timestamp({ t: 1695291593, i: 4 })
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial/t-relate-mongodb.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ Notice that in the previous step when you typed `juju run-action data-integrator
```shell
juju ssh mongodb/0
```
Then access `mongo` with the URI that you copied above:
Then access `mongosh` with the URI that you copied above:

```shell
charmed-mongodb.mongo "<uri copied from juju run-action data-integrator/leader get-credentials --wait>"
charmed-mongodb.mongosh "<uri copied from juju run-action data-integrator/leader get-credentials --wait>"
```
***Note: be sure you wrap the URI in `"` with no trailing whitespace*.**

Expand Down

0 comments on commit 2482871

Please sign in to comment.