§2023-07-24

  1. Connect to a Local Deployment
    • mongosh is the same as mongosh mongodb://localhost:27017
    • mongosh is the same as mongosh "mongodb://localhost:27017"
      • enclosed in " quotes is not necessary
$ mongosh mongodb://redisMongo01.yushei.com.tw:27017,redisMongo02.yushei.com.tw:27017,redisMongo03.yushei.com.tw:27017/YuSheiDB?replicaSet=ys20220318
Current Mongosh Log ID:	64be155bf83dd70f33f9ac68
Connecting to:		mongodb://redisMongo01.yushei.com.tw:27017,redisMongo02.yushei.com.tw:27017,redisMongo03.yushei.com.tw:27017/YuSheiDB?replicaSet=ys20220318&appName=mongosh+1.10.1
Using MongoDB:		5.0.8
Using Mongosh:		1.10.1

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

ys20220318 [primary] YuSheiDB> 
 mongosh mongodb://ysadmin:yushei23258585@redisMongo01.yushei.com.tw:27017,redisMongo02.yushei.com.tw:27017,redisMongo03.yushei.com.tw:27017/YuSheiDB?replicaSet=ys20220318
Current Mongosh Log ID:	64be15c7b1692f213a5a8772
Connecting to:		mongodb://<credentials>@redisMongo01.yushei.com.tw:27017,redisMongo02.yushei.com.tw:27017,redisMongo03.yushei.com.tw:27017/YuSheiDB?replicaSet=ys20220318&appName=mongosh+1.10.1
Using MongoDB:		5.0.8
Using Mongosh:		1.10.1

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

ys20220318 [primary] YuSheiDB> 
  1. Connect With Authentication
$ mongosh "mongodb://redisMongo01.yushei.com.tw:27017,redisMongo02.yushei.com.tw:27017,redisMongo03.yushei.com.tw:27017/YuSheiDB?replicaSet=ys20220318" --username ysadmin --authenticationDatabase
Enter password: **************
Current Mongosh Log ID:	64be18bd0d554113149c2944
Connecting to:		mongodb://<credentials>@redisMongo01.yushei.com.tw:27017,redisMongo02.yushei.com.tw:27017,redisMongo03.yushei.com.tw:27017/YuSheiDB?replicaSet=ys20220318&appName=mongosh+1.10.1
Using MongoDB:		5.0.8
Using Mongosh:		1.10.1

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

ys20220318 [primary] YuSheiDB> 
#!/bin/bash

# on orhpi5ach.yushei.net

 mongosh "mongodb://orgpi5arch.yushei.net:27999/?tls=true&tlsCertificateKeyFile=/opt/xfs/mongodb/x.509/orgpi5arch.yushei.net.pem&tlsCAFile=/opt/xfs/mongodb/x.509/mongoCA.crt"
#!/bin/bash

 mongosh "mongodb://orgpi5arch.yushei.net:27999/?tls=true&tlsCertificateKeyFile=/opt/xfs/mongodb/x.509/orgpi5arch.yushei.net.pem&tlsCAFile=/opt/xfs/mongodb/x.509/mongoCA.crt"
[alexlai@orgpi5Arch ~]$ cat ~/.mongoshrc.js 
// .mongoshrc

// Configuration for connecting to the MongoDB instance
// running on port 27999 locally.

//  mongosh "mongodb://orgpi5arch.yushei.net:27999/?tls=true&tlsCertificateKeyFile=/opt/xfs/mongodb/x.509/orgpi5arch.yushei.net.pem&tlsCAFile=/opt/xfs/mongodb/x.509/mongoCA.crt"

// db = connect("mongodb://localhost:27999/admin");

// db.auth();

console.log("Hi! from orgpi5Arch.yushei.net:27999");

// db = connect("mongodb://siteRootAdmin:b23258585@orgpi5Arch.yushei.net:27999,hc4Jammy.yushei.net:27999,h2Jammy.yushei.net:27999/?replicaSet=MuneTakaHome&authSource=admin");
db = connect("mongodb://siteRootAdmin:b23258585@orgpi5arch.yushei.net:27999,orgpi5jammy.yushei.net:27999,n2mnjaro.yushei.net.yushei.net:27999/?replicaSet=MuneTakaHome&authSource=admin&tls=true&tlsCertificateKeyFile=/opt/xfs/mongodb/x.509/orgpi5arch.yushei.net.pem&tlsCAFile=/opt/xfs/mongodb/x.509/mongoCA.crt");


// let log =  rs.status().members;
// console.table(log);


function alert() {
        let log =  rs.status().members;
        let simpleLog = [];
        // console.log(log);
        for (let i = 0; i < log.length; i++){
            // console.log("_id: ", log[i]._id, "name: ", log[i].name, "health: ", log[i].health, "state: ", log[i].state, "stateStr: ", log[i].stateStr);
                simpleLog[i] = {
                        "_id": log[i]._id,
                        "name": log[i].name,
                        "health": log[i].health,
                        "state": log[i].state,
                        "stateStr": log[i].stateStr
                }
        }
        console.log('\n');
        console.table(simpleLog);
        console.log(Date().toLocaleString());
}

alert();

let timerId =  setInterval(() => alert(), 60000); // 単位 is milli-second, 1 sec = 1000