gpt4 book ai didi

python - 构建 Firebase 数据库

转载 作者:行者123 更新时间:2023-12-01 03:31:57 25 4
gpt4 key购买 nike

我正在关注this构建 Firebase 数据的教程。接近尾声时,它说:

With this kind of structure, you should keep in mind to update the data at 2 locations under the user and group too. Also, I would like to notify you that everywhere on the Internet, the object keys are written like "user1","group1","group2" etc. where as in practical scenarios it is better to use firebase generated keys which look like '-JglJnGDXcqLq6m844pZ'. We should use these as it will facilitate ordering and sorting.

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

enter image description here

enter image description here

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

我怎样才能实现这个目标?

最佳答案

当您使用这样的行将数据写入 Firebase 数组(例如在 Javascript 中)时

var newPostKey = firebase.database().ref().child('users').push().key;

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

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

如描述here ,您将获得“推送”数据的生成 key 。在上面的示例中 newPostKey 将包含此生成的 key

更新
要使用 Python 包装器回答更新的问题:
在您链接到的页面中查找“保存数据”部分。

代码看起来像这样;

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)

关于python - 构建 Firebase 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40873414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com