1
1

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-01-24

こちらで作成したデータを更新します。
Python3 で Cloud Firestore のデータを作成 (Create)

firestore_update.py
#! /usr/bin/python
#
import sys
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore

# ------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
key_in = sys.argv[1]
population_in = int(sys.argv[2])
#
print("%s\t%d" % (key_in, population_in))
#
project = 'project-aaa'
#
cred = credentials.ApplicationDefault()
firebase_admin.initialize_app(cred, {
  'projectId': project,
})

db = firestore.client()
#
city_ref = db.collection('cities').document(key_in)
city_ref.update({'population': population_in})
#
sys.stderr.write("*** 終了 ***\n")
# ------------------------------------------------------------------

実行コマンド

export GOOGLE_APPLICATION_CREDENTIALS="***.json"
./firestore_update.py t0922 98456200

次のバージョンで確認しました。

$ python --version
Python 3.8.6
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1