如何使用python从Firebase数据库检索路径的数据? [英] How do I retrieve a path's data from firebase database using python?

查看:35
本文介绍了如何使用python从Firebase数据库检索路径的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个Firebase数据库结构

I have this firebase database structure

我想为企业"下的每个ID打印出库存清单(Inventory).
所以我尝试了这段代码

I want to print out the inventory list(Inventory) for each ID under Businesses.
So I tried this code

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

但是我只有这个

  <pyrebase.pyrebase.Database object at 0x1091eada0>

我在做错什么,如何遍历每个企业ID并打印出其库存?

what am I doing wrong and how can I loop through each Business ID and print out their inventory?

推荐答案

首先,您正在打印数据库对象.您需要保持数据静止.

First, you're printing a Database object. You need to get the data still.

您似乎已经知道如何以及孩子们.或者您只是复制了示例而没有理解...

You seem to already know how to get that as well as the children. Or you only copied the examples without understanding it...

无论哪种方式,您都可以尝试

Either way, you can try this

db = firebase.database() 
businesses = db.child("Businesses")
for userid in businesses.shallow().get().each():
    inventory = businesses.child(userid).child("Inventory").get()
    print( inventory.val() )

在旁注中, National_Stock_Numbers 看起来应该是名称的值,而不是孩子的键

On a side note, National_Stock_Numbers looks like it should be a value of the name, not a key for a child

这篇关于如何使用python从Firebase数据库检索路径的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆