curl で Cloud Firestore のデータを更新 (Update)


Cloud Firestore の RestAPI を使ってデータを更新します。

update01.json
{
  "fields": {
    "population": { "integerValue": "27513000" },
    "date_mod": { "stringValue": "2020-06-01" }
  }
}

project-aaa の cities の t0921 を更新

firestore_update.sh
#
#
#
export GOOGLE_APPLICATION_CREDENTIALS="***.json"
#
ACCESS_TOKEN=`gcloud auth application-default print-access-token`
#
project_id=`jq .project_id $GOOGLE_APPLICATION_CREDENTIALS | sed "s/\"//g"`
echo $project_id
#
URL='https://firestore.googleapis.com/v1/projects/'$project_id'/databases/(default)/documents/cities/t0921'
#
#
curl -H "Authorization: Bearer $ACCESS_TOKEN" \
    -H 'Content-Type: application/json' \
    -X PATCH \
    -d@update01.json \
    $URL"?updateMask.fieldPaths=population&updateMask.fieldPaths=date_mod"
#
#