如何在Firebase实时数据库中使用Python递增数值?

huangapple go评论64阅读模式
英文:

How to increment values in firebase realtime database python?

问题

抱歉,我无法让你的请求保持代码部分不被翻译。以下是你要翻译的内容:

"I have the exact same question as this one but in python :

https://stackoverflow.com/questions/70045141/how-to-increment-values-in-firebase-realtime-database-v9

Is it actually implemented or not ? Because i am unable to find how to perform a :

from firebase_admin import db

realtime_db = db.reference(path="/", app=app, url="myurl")
realtime_db.update({
   f"chats/{uid}/num": db.increment(1),
})

Thanks in advance"

英文:

I have the exact same question as this one but in python :

https://stackoverflow.com/questions/70045141/how-to-increment-values-in-firebase-realtime-database-v9

Is it actually implemented or not ? Because i am unable to find how to perform a :

from firebase_admin import db

realtime_db = db.reference(path="/", app=app, url="myurl")
realtime_db.update({
   f"chats/{uid}/num": db.increment(1),
})

Thanks in advance

答案1

得分: 2

根据Python Admin SDK的文档 ,似乎没有increment操作的实现。

幸运的是,该操作只是提供一个用于发送到服务器的标记值,您也可以根据REST API文档中的示例创建自己的。应该类似于这样:

realtime_db.update({
   f"chats/{uid}/num": { ".sv": { "increment": 1 }},
})

上面示例中可能存在语法错误,如果遇到任何错误,请通知我以进行修复。

英文:

From looking at the documentation of the Python Admin SDK there doesn't seem to be an implementation of the increment operation there.

Luckily, that operation just gives you a sentinel value to send to the server, and you can create that yourself too based on the example in the documentation for the REST API. It should be something like this:

realtime_db.update({
   f"chats/{uid}/num": { ".sv": { "increment": 1 }},
})

Syntax errors in the above example are definitely possible, so let me know about any of those you encounter and fix below please.

huangapple
  • 本文由 发表于 2023年2月17日 23:40:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75486368.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定