Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 引用必要套件
- import firebase_admin
- from firebase_admin import credentials
- from firebase_admin import firestore
- # 引用私密金鑰
- # path/to/serviceAccount.json 請用自己存放的路徑
- cred = credentials.Certificate('serviceAccount.json')
- # 初始化firebase,注意不能重複初始化
- firebase_admin.initialize_app(cred)
- # 初始化firestore
- db = firestore.client()
- doc = {
- 'name': "帽子哥",
- 'email': "abc@gmail.com"
- }
- # 語法
- # collection_ref = db.collection("集合路徑")
- collection_ref = db.collection("pyradise_students")
- # collection_ref提供一個add的方法,input必須是文件,型別是dictionary
- collection_ref.add(doc)
Add Comment
Please, Sign In to add comment