如何在firebase(python)上推送多个新对象
我希望将数据从json推送到firebase,而不为每个对象生成新密钥。理想情况下,我希望定义密钥的名称 这是我的密码:如何在firebase(python)上推送多个新对象,python,json,firebase-realtime-database,pyrebase,Python,Json,Firebase Realtime Database,Pyrebase,我希望将数据从json推送到firebase,而不为每个对象生成新密钥。理想情况下,我希望定义密钥的名称 这是我的密码: import pyrebase import json config = {my firebase config} firebase = pyrebase.initialize_app(config) db = firebase.database() with open('myjson.json') as response: data = json.load(re
import pyrebase
import json
config = {my firebase config}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
with open('myjson.json') as response:
data = json.load(response)
db.child("customer").push(data)
我的json如下所示:
{
"first_customer": {
"createdat": "2019-08-09T06:40:10+0000",
"expires": 1572039000.0,
},
"second_customer": {
"createdat": "2019-08-09T06:33:39+0000",
"expires": 1570048200.0,
}
}
但实际上我的代码在firebase上给了我这样的信息:
"customer": {
"-Lm_M6OM7MCV3_PFvcSH(random_id_given_by_firebase)": {
"first_customer": {
"createdat": "2019-08-09T06:40:10+0000",
"expires": 1572039000.0,
},
"second_customer": {
"createdat": "2019-08-09T06:33:39+0000",
"expires": 1570048200.0,
}
}
}
我所期望的是:
"customer": {
"first_customer": {
"createdat": "2019-08-09T06:40:10+0000",
"expires": 1572039000.0,
},
"second_customer": {
"createdat": "2019-08-09T06:33:39+0000",
"expires": 1570048200.0,
}
}
要控制完整路径,请使用。比如:
db.child("customer").child("keyforcustomer").set(data)
要控制完整路径,请使用。比如:
db.child("customer").child("keyforcustomer").set(data)
我刚刚做了db.child(“客户”).set(数据),它工作正常!感谢您的帮助,Franki刚刚完成了db.child(“客户”).set(数据)并且工作正常!谢谢你的帮助,弗兰克