构建Firebase数据库

时间:2016-11-29 18:43:48

标签: python firebase firebase-realtime-database

我正在关注this教程来构建Firebase数据。接近结束时,它说:

  

使用这种结构时,您应该记住在用户和组下的2个位置更新数据。此外,我想通知你,在互联网上的任何地方,对象键都写成“user1”,“group1”,“group2”等。在实际情况中,最好使用firebase生成的键,看起来像' -JglJnGDXcqLq6m844pZ”。我们应该使用它们,因为它将有助于订购和分类。

基于此,我假设最终结果应该如下:

enter image description here

enter image description here

我正在使用this python wrapper发布数据。

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:2)

使用类似

的行将数据写入Firebase数组时(例如在Javascript中)
var newPostKey = firebase.database().ref().child('users').push().key;

var updates = {item1: value1, item2: value2};

return firebase.database().ref().update(updates);

here所述,您将获得生成的数据密钥"推送"。在上面的示例中,newPostKey将包含此生成的密钥

<强>更新
使用Python包装器回答更新的问题:
寻找&#34;保存数据&#34;在您链接的页面中。

代码看起来像这样;

data = {"Title": "The Animal Book"}
book = db.child("AllBooks").push(data)

data = {"Title": "Animals"}
category = db.child("Categories").push(data)

data = {category['name']: true }
db.child("AllBooks").child(book['name']).child("categories").push(data)
相关问题