2017-09-10 48 views
0

我有這個數據庫結構如何使用python獲取嵌套位置的firebase數據庫數據?

enter image description here

每個業務ID有庫存,在庫存,也有很多項目,每個項目都有類似名稱,零件編號和NSN許多屬性。 我需要得到所有NSNS每個存貨項目到一個數組所以我嘗試此代碼,它

db = firebase.database() 
Businesses = db.child("Businesses").get() 
for user in Businesses.each(): 
userid = user.key() 
inventorydb = db.child("Businesses").child(userid).child("Inventory").get() 

#looping through inventory child 

for item in inventorydb.each(): 
    itemid = item.key() 
    itemdb = db.child("Businesses").child(userid).child("Inventory").child(itemid).get() 
print(itemdb.val("NSN")) 

其他的變化,但所有我不斷收到這個錯誤是

val() takes 1 positional argument but 2 were given 

哪能獲取每個庫存項目的所有NSN?

回答

0

好,看着文檔中,val()函數返回快照的字典

你可能想

print(itemdb.val()["NSN"]) 

我也建議你重寫火力地堡結構爲「avoid building nests

相關問題