简体   繁体   English

Firebase 实时数据库更新子

[英]Firebase realtime DB update child

I have a "Users" data structure like this , I want to increment the value of ttl_user by 1 when a user is signed up.我有一个像这样的“用户”数据结构,我想在用户注册时将ttl_user的值增加 1。 And decrement it by 1 when a user has deleted their account.当用户删除其帐户时,将其减 1。

How can I update the value?如何更新值? Thanks.谢谢。

In your particular case, it would be as simple as:在您的特定情况下,它很简单:

DatabaseReference db = FirebaseDatabase.getInstance().getReference();
DatabaseReference userRef = db.child("User");
userRef.child("ttl_user").setValue(ServerValue.increment(1));

And to decrement, simply pass a negative value -1 .而要递减,只需传递一个负值-1

I'm not able to comment can you please tell me if this "ttl_user" is all user value or a particular one user value if this is All User Value Than You Need To maintain one Variable.我无法发表评论,您能否告诉我这个“ttl_user”是所有用户值还是特定的一个用户值,如果这是所有用户值,而不是您需要维护一个变量。 That's Help to Archive this issue.这是存档此问题的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase 实时数据库多文档更新失败 - Firebase Realtime DB multi-document update failing 有没有办法用 Firebase 禁用实时更新? - Is there way to disable realtime update with Firebase? JavaScript/Firebase:如何在 Firebase 实时数据库中存储 URL? - JavaScript/Firebase: How to store an URL in Firebase realtime DB? 无法从本地存储 Firebase 实时数据库中匹配孩子的孩子 - Unable to match child of a child from local storage Firebase RealTime database 如何使用 Firebase 9(模块化 sdk)更新 Firebase 实时数据库中的数据 - How to update data in Firebase realtime database using Firebase 9 (modular sdk) 通过Firebase实时数据库中的子节点获取父节点 - Getting parent node through child node in Firebase Realtime database 在 web 上收听 child_changed(Firebase 实时数据库) - Listen to child_changed (Firebase Realtime Database) on web 如何从 firebase 实时数据库中获取不同孩子的值? - How to get values from different child in firebase realtime database? 从 Firebase 实时数据库子项中获取单个事件 - Fetching Single Event From a Firebase Realtime Database Child 将新属性更新到现有节点 firebase(实时数据库) - update new attribute into exists node firebase(realtime database)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM