如何使用副本集在安静模式下使用mongo shell

问题描述 投票:2回答:1

[当我尝试使用--eval执行javascript代码时,mongo shell会生成额外的输出,--quiet选项似乎不起作用

check_mongodb_availability() {
  local hostname=$1
  local database=$2
  local js=" var found = 0;
             var dbs = db.getMongo().getDBNames();
              for(var i in dbs) {
                if (dbs[i].toString() == '"${database}"') found = 1;
              }
              if (found === 1) print(true); else print(false);
           "

  if [ $(mongo --host $hostname --eval "$js" --quiet) == "true" ]; then
    return 1
  else
    return 0
  fi
}

上面的函数无法说'参数太多'

它在下面输出]

2019-10-10T10:37:57.262+0000 I NETWORK [js] Starting new replica set monitor for replicaSet/172.31.79.62:27017,172.31.69.171:27017,172.31.73.190:27017 2019-10-10T10:37:57.263+0000 I NETWORK [js] Successfully connected to 172.31.69.171:27017 (1 connections now open to 172.31.69.171:27017 with a 5 second timeout) 2019-10-10T10:37:57.263+0000 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to 172.31.79.62:27017 (1 connections now open to 172.31.79.62:27017 with a 5 second timeout) 2019-10-10T10:37:57.264+0000 I NETWORK [js] changing hosts to replicaSet/172.31.79.62:27017,mongodb-replica-2:27017,mongodb-replica-3:27017 from replicaSet/172.31.69.171:27017,172.31.73.190:27017,172.31.79.62:27017 2019-10-10T10:37:57.265+0000 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to mongodb-replica-2:27017 (1 connections now open to mongodb-replica-2:27017 with a 5 second timeout) 2019-10-10T10:37:57.265+0000 I NETWORK [js] Successfully connected to mongodb-replica-3:27017 (1 connections now open to mongodb-replica-3:27017 with a 5 second timeout) true

我需要通过避免所有额外的干扰来仅打印“ true”或“ false”

对此非常感谢!

[当我尝试使用--eval执行javascript代码时,mongo shell会生成额外的输出,--quiet选项似乎不起作用check_mongodb_availability(){本地主机名= $ 1本地数据库= $ 2 ...

mongodb bash mongo-shell mongodb-replica-set
1个回答
0
投票

[不幸的是,这似乎是一个主动漏洞,于2016年首次启动...

© www.soinside.com 2019 - 2024. All rights reserved.