curl で Cloud Firestore のデータを作成
Cloud Firestore の RestAPI を使ってデータを作成します。
in01.json
{
"fields": {
"name": { "stringValue": "宇都宮" },
"population": { "integerValue": "7592100" },
"date_mod": { "stringValue": "2020-01-27" }
}
}
in02.json
{
"fields": {
"name": { "stringValue": "小山" },
"population": { "integerValue": "3592100" },
"date_mod": { "stringValue": "2020-01-27" }
}
}
in03.json
{
"fields": {
"name": { "stringValue": "佐野" },
"population": { "integerValue": "9214600" },
"date_mod": { "stringValue": "2020-01-27" }
}
}
GOOGLE_APPLICATION_CREDENTIALS で定義されている project の cities に書き込み
firestore_create.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?documentId='
#
curl -H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-X POST -d@in01.json $URL"t0921"
#
curl -H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-X POST -d@in02.json $URL"t0922"
#
curl -H "Authorization: Bearer $ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-X POST -d@in03.json $URL"t0923"
#
Author And Source
この問題について(curl で Cloud Firestore のデータを作成), 我々は、より多くの情報をここで見つけました https://qiita.com/ekzemplaro/items/c0db65d7a75a874d48e4著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .