使用 'jq' JSON shell 工具搜索和替换
search and replace with 'jq' JSON shell tool
此处从 JSON 输出中提取。 JSON 文档 automationConfig 是 MongoDB Ops Manager,一个用于管理 mongod
.
的商业产品
$ cat automationConfig | jq '.processes[]'
{
"args2_6": {
"net": {
"port": 28200
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-cache-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-cache-dbspace/wooomtest-cache-dbspace_0",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-cache-dbspace/wooomtest-cache-dbspace_0/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-ca-sc-wooom-stack4-prd-1.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-cache-dbspace_0",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28200
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-cache-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-cache-dbspace/wooomtest-cache-dbspace_1",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-cache-dbspace/wooomtest-cache-dbspace_1/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-ca-sc-wooom-stack4-prd-2.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-cache-dbspace_1",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28200
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-cache-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-cache-dbspace/wooomtest-cache-dbspace_2",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-cache-dbspace/wooomtest-cache-dbspace_2/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-ca-sc-wooom-stack4-prd-3.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-cache-dbspace_2",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28000
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-identity-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-identity-dbspace/wooomtest-identity-dbspace_3",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-identity-dbspace/wooomtest-identity-dbspace_3/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-id-sc-wooom-stack4-prd-1.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-identity-dbspace_3",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28000
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-identity-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-identity-dbspace/wooomtest-identity-dbspace_4",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-identity-dbspace/wooomtest-identity-dbspace_4/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-id-sc-wooom-stack4-prd-2.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-identity-dbspace_4",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28000
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-identity-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-identity-dbspace/wooomtest-identity-dbspace_5",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-identity-dbspace/wooomtest-identity-dbspace_5/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-id-sc-wooom-stack4-prd-3.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-identity-dbspace_5",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28300
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-library-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-library-dbspace/wooomtest-library-dbspace_6",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-library-dbspace/wooomtest-library-dbspace_6/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-lib-sc-wooom-stack4-prd-1.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-library-dbspace_6",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28300
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-library-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-library-dbspace/wooomtest-library-dbspace_7",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-library-dbspace/wooomtest-library-dbspace_7/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-lib-sc-wooom-stack4-prd-2.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-library-dbspace_7",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28300
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-library-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-library-dbspace/wooomtest-library-dbspace_8",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-library-dbspace/wooomtest-library-dbspace_8/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-lib-sc-wooom-stack4-prd-3.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-library-dbspace_8",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28100
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-storage-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-storage-dbspace/wooomtest-storage-dbspace_9",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-storage-dbspace/wooomtest-storage-dbspace_9/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-st-sc-wooom-stack4-prd-1.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-storage-dbspace_9",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28100
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-storage-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-storage-dbspace/wooomtest-storage-dbspace_10",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-storage-dbspace/wooomtest-storage-dbspace_10/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-st-sc-wooom-stack4-prd-2.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-storage-dbspace_10",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28100
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-storage-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-storage-dbspace/wooomtest-storage-dbspace_11",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-storage-dbspace/wooomtest-storage-dbspace_11/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-st-sc-wooom-stack4-prd-3.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-storage-dbspace_11",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28400
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-support-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-support-dbspace/wooomtest-support-dbspace_12",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-support-dbspace/wooomtest-support-dbspace_12/mongodb.log"
}
},
"authSchemaVersion": 5,
"hostname": "node-z5-wooomtest-sup-sc-wooom-stack4-prd-1.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-support-dbspace_12",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28400
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-support-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-support-dbspace/wooomtest-support-dbspace_13",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-support-dbspace/wooomtest-support-dbspace_13/mongodb.log"
}
},
"authSchemaVersion": 5,
"hostname": "node-z5-wooomtest-sup-sc-wooom-stack4-prd-2.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-support-dbspace_13",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28400
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-support-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-support-dbspace/wooomtest-support-dbspace_14",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-support-dbspace/wooomtest-support-dbspace_14/mongodb.log"
}
},
"authSchemaVersion": 5,
"hostname": "node-z5-wooomtest-sup-sc-wooom-stack4-prd-3.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-support-dbspace_14",
"processType": "mongod",
"version": "3.0.7"
}
我只能提取版本
$ cat automationConfig | jq '.processes[] .version'
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
现在我想使用 shell 工具 jq
将数字“3.0.7”替换为“3.0.6”。
我正在关注此 docs.mongodb.com,但希望降级(而不是升级)。
搜索具有您要更新的版本的进程,然后更新它们。
(.processes[] | select(.version == "3.0.7")).version = "3.0.6"
现在您已经提取了所需的值,接下来只需为它们分配一个新值即可。
$ cat automationConfig | jq '.processes[].version = "3.0.6"'
此处从 JSON 输出中提取。 JSON 文档 automationConfig 是 MongoDB Ops Manager,一个用于管理 mongod
.
$ cat automationConfig | jq '.processes[]'
{
"args2_6": {
"net": {
"port": 28200
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-cache-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-cache-dbspace/wooomtest-cache-dbspace_0",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-cache-dbspace/wooomtest-cache-dbspace_0/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-ca-sc-wooom-stack4-prd-1.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-cache-dbspace_0",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28200
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-cache-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-cache-dbspace/wooomtest-cache-dbspace_1",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-cache-dbspace/wooomtest-cache-dbspace_1/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-ca-sc-wooom-stack4-prd-2.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-cache-dbspace_1",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28200
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-cache-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-cache-dbspace/wooomtest-cache-dbspace_2",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-cache-dbspace/wooomtest-cache-dbspace_2/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-ca-sc-wooom-stack4-prd-3.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-cache-dbspace_2",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28000
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-identity-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-identity-dbspace/wooomtest-identity-dbspace_3",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-identity-dbspace/wooomtest-identity-dbspace_3/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-id-sc-wooom-stack4-prd-1.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-identity-dbspace_3",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28000
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-identity-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-identity-dbspace/wooomtest-identity-dbspace_4",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-identity-dbspace/wooomtest-identity-dbspace_4/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-id-sc-wooom-stack4-prd-2.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-identity-dbspace_4",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28000
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-identity-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-identity-dbspace/wooomtest-identity-dbspace_5",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-identity-dbspace/wooomtest-identity-dbspace_5/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-id-sc-wooom-stack4-prd-3.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-identity-dbspace_5",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28300
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-library-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-library-dbspace/wooomtest-library-dbspace_6",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-library-dbspace/wooomtest-library-dbspace_6/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-lib-sc-wooom-stack4-prd-1.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-library-dbspace_6",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28300
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-library-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-library-dbspace/wooomtest-library-dbspace_7",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-library-dbspace/wooomtest-library-dbspace_7/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-lib-sc-wooom-stack4-prd-2.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-library-dbspace_7",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28300
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-library-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-library-dbspace/wooomtest-library-dbspace_8",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-library-dbspace/wooomtest-library-dbspace_8/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-lib-sc-wooom-stack4-prd-3.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-library-dbspace_8",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28100
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-storage-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-storage-dbspace/wooomtest-storage-dbspace_9",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-storage-dbspace/wooomtest-storage-dbspace_9/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-st-sc-wooom-stack4-prd-1.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-storage-dbspace_9",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28100
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-storage-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-storage-dbspace/wooomtest-storage-dbspace_10",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-storage-dbspace/wooomtest-storage-dbspace_10/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-st-sc-wooom-stack4-prd-2.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-storage-dbspace_10",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28100
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-storage-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-storage-dbspace/wooomtest-storage-dbspace_11",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-storage-dbspace/wooomtest-storage-dbspace_11/mongodb.log"
}
},
"authSchemaVersion": 5,
"disabled": false,
"hostname": "node-z5-wooomtest-st-sc-wooom-stack4-prd-3.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-storage-dbspace_11",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28400
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-support-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-support-dbspace/wooomtest-support-dbspace_12",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-support-dbspace/wooomtest-support-dbspace_12/mongodb.log"
}
},
"authSchemaVersion": 5,
"hostname": "node-z5-wooomtest-sup-sc-wooom-stack4-prd-1.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-support-dbspace_12",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28400
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-support-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-support-dbspace/wooomtest-support-dbspace_13",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-support-dbspace/wooomtest-support-dbspace_13/mongodb.log"
}
},
"authSchemaVersion": 5,
"hostname": "node-z5-wooomtest-sup-sc-wooom-stack4-prd-2.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-support-dbspace_13",
"processType": "mongod",
"version": "3.0.7"
}
{
"args2_6": {
"net": {
"port": 28400
},
"operationProfiling": {},
"replication": {
"replSetName": "wooomtest-support-dbspace"
},
"storage": {
"dbPath": "/data/wooomtest-support-dbspace/wooomtest-support-dbspace_14",
"engine": "wiredTiger"
},
"systemLog": {
"destination": "file",
"path": "/data/wooomtest-support-dbspace/wooomtest-support-dbspace_14/mongodb.log"
}
},
"authSchemaVersion": 5,
"hostname": "node-z5-wooomtest-sup-sc-wooom-stack4-prd-3.sc-wooom-stack4-prd.local",
"logRotate": {
"sizeThresholdMB": 1000,
"timeThresholdHrs": 24
},
"name": "wooomtest-support-dbspace_14",
"processType": "mongod",
"version": "3.0.7"
}
我只能提取版本
$ cat automationConfig | jq '.processes[] .version'
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
"3.0.7"
现在我想使用 shell 工具 jq
将数字“3.0.7”替换为“3.0.6”。
我正在关注此 docs.mongodb.com,但希望降级(而不是升级)。
搜索具有您要更新的版本的进程,然后更新它们。
(.processes[] | select(.version == "3.0.7")).version = "3.0.6"
现在您已经提取了所需的值,接下来只需为它们分配一个新值即可。
$ cat automationConfig | jq '.processes[].version = "3.0.6"'