问题描述
限时送ChatGPT账号..我有下一个数据库列表(用户名 + 用户 ID).
如何通过用户 ID 查找对象并更改其密钥(用户名)?
我在 Angular 5 中使用 AngularFire2.
解决方案您可以使用如下查询通过其值查找子节点:
var users = firebase.database().reference("usernames");var query = users.orderByValue().equalTo("Sk6I..."ltA2");
通过将侦听器附加到此查询,您将能够找到与 UID 匹配的用户(或任何用户",因为技术上可能有更多具有相同值的键)的引用和键.>
但是您不能重命名节点.您必须删除现有节点,然后创建一个新节点.有关更多信息,请参阅:
Firebase:更新密钥?Firebase API 用于将树枝从一个集合移动到另一个集合是否可以重命名Firebase 实时数据库中的键?I have next database list (usernames + user id).
How can i find object by user id and change his key (username)?
I'm using AngularFire2 with Angular 5.
解决方案You can find a child node by its value with a query like this:
var users = firebase.database().reference("usernames");
var query = users.orderByValue().equalTo("Sk6I..."ltA2");
By attaching a listener to this query you'll be able to find the reference and the key of the user (or "any users", since technically there may be more keys with the same value) matching the UID.
But you can't rename a node. You'll have to remove the existing node, and create a new one. For more on this see:
Firebase: Update key? Firebase API for moving a tree branch from a collection to another one Is it possible to rename a key in the Firebase Realtime Database?这篇关于通过一个值在 Firebase 中查找对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论