python - 如何使用 requests、Python 和 Firebase 添加数据而不是替换数据

标签 python rest firebase python-requests

我正在使用 requests 模块在 Firebase 中获取和设置数据。假设我有一个现有的火力基地,http://mytest.firebaseio.com ,看起来像这样

|somewhere
  |--test1
    |--exists: 1

我想向其中添加数据,所以它看起来像:

|somewhere
  |--test1
    |--exists: 1
    |--arrived: 1

我的直觉是使用put(),例如:

r = requests.put('http://mytest.firebaseio.com/test1.json',data='{"arrived":1}')

但这会导致删除除了添加arrived: 1之外的exists: 1,例如:

|somewhere
  |--test1
    |--arrived: 1

如何添加 arrived: 1 而不删除 exists: 1

最佳答案

来自docs :

You can update specific children at a location without overwriting existing data with a PATCH request. Named children in the data being written with PATCH will be written, but omitted children will not be deleted. This is equivalent to the update( ) function.

所以你想使用 requests.patch() 而不是 requests.put()

关于python - 如何使用 requests、Python 和 Firebase 添加数据而不是替换数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22430619/

相关文章:

python - 使用 num_labels 1 vs 2 的 huggingface 变形金刚分类

javascript - 如何使用 Firebase 在 Ionic 3 中通过参数检索数据

Python 异步回调和生成器

python - 如何在 DataFrame 中存储 DataFrame

java - Jersey 方法不允许 405

java - 如何从 Foursquare 获取访问 token ?

java - 泽西客户端 : Array of Strings as param

ios - 与 FlutterFire 和 iOS 上的原生 GeoFire 插件冲突

javascript - 使用 URL 设置变量

python - 无法让我的大炮在 pygame 中发射子弹