gpt4 book ai didi

mongodb - 如何使用副本集以安静模式进行 mongo shell

转载 作者:行者123 更新时间:2023-12-03 15:59:31 24 4
gpt4 key购买 nike

当我尝试使用 --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”

最佳答案

不幸的是,这是一个在 2016 年首次出现的活跃 bug...

https://jira.mongodb.org/browse/SERVER-27159

两种可能的解决方法:

  • 从主机列表中删除副本集名称。例如: host-1:27017,host-2:27017,host-3:27017 而不是 my-replica-set:host-1:27017,host-2:27017,host -3:27017
  • 通过 tail 管道输出

关于mongodb - 如何使用副本集以安静模式进行 mongo shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58321682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com