在Firebase中按一个值查找对象 [英] Find object in Firebase by one value

查看:64
本文介绍了在Firebase中按一个值查找对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个数据库列表(用户名+用户ID).

I have next database list (usernames + user id).

如何通过用户ID查找对象并更改其键(用户名)?

How can i find object by user id and change his key (username)?

我在Angular 5中使用AngularFire2.

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");

通过将侦听器附加到此查询,您将能够找到与UID匹配的用户(或任何用户",因为从技术上讲,可能有更多具有相同值的键)的引用和键.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆