c48491581116862776108ac2f85cc76fdee74cd4
configuration/updateTracTracApiTokenForArchive.sh
| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | +#!/bin/bash |
|
| 2 | +if [ -z "${1}" -o "-h" = "${1}" ]; then |
|
| 3 | + echo "Usage: ${0} {MONGO_URI} {NEW_API_TOKEN} [ {OLD_API_TOKEN_TO_REPLACE} ]" |
|
| 4 | + echo "" |
|
| 5 | + echo "Sets a new API token in the MONGO DB whose URI is given. This affects" |
|
| 6 | + echo "the tracTracApiToken field in the CONNECTIVITY_PARAMS_FOR_RACES_TO_BE_RESTORED" |
|
| 7 | + echo "collection." |
|
| 8 | + echo "If the optional OLD_API_TOKEN_TO_REPLACE is provided, only those records will" |
|
| 9 | + echo "be updated that have an existing tracTracApiToken equal to the old API token." |
|
| 10 | +else |
|
| 11 | + MONGO_URI="${1}" |
|
| 12 | + TOKEN="${2}" |
|
| 13 | + OLD_TOKEN="${3}" |
|
| 14 | + if [ -n "${OLD_TOKEN}" ]; then |
|
| 15 | + FILTER_FOR_OLD_TOKEN=', "tracTracApiToken": "'${OLD_TOKEN}'"' |
|
| 16 | + else |
|
| 17 | + FILTER_FOR_OLD_TOKEN="" |
|
| 18 | + fi |
|
| 19 | + mongosh --quiet --eval 'EJSON.stringify(db.CONNECTIVITY_PARAMS_FOR_RACES_TO_BE_RESTORED.updateMany({"type": "TRAC_TRAC"'"${FILTER_FOR_OLD_TOKEN}"'}, {$set: {"tracTracApiToken": "'${TOKEN}'"}}, {multi: true}))' "${MONGO_URI}" |
|
| 20 | +fi |