Firebase - 从配置文件列表中按用户 ID 获取对象

Firebase - Get object by userID from a list of profiles

我正在尝试使用 Firebase 从配置文件列表中按用户 ID 获取对象。

我正在使用 Typescript 在 Angular2 中编码。 我已经获得了对 firebase 工作的引用,并且可以执行其他命令,例如推送对象等。

我只需要知道如何通过字段值提取对象,例如在本例中为 uid。

这是我的代码片段:

getUserProfileByUid(uid){
    console.log("Get profile by uid");

    var ref = new Firebase("https://markng2.firebaseio.com/profiles/uid");
    var data = ref.child(uid);

    console.log(data));     
}

*查看我的 firebase 配置文件的照片 json。

提前致谢。

您可以使用查询。

var rootRef = new Firebase('<my-firebase-app>.firebaseio.com/');
var profileRef = rootRef.child('profiles');

// order by email and then find the specific email
var query = profileRef.orderByChild('email').equalTo('myemail@email.com');

// Do a one time read of that email
query.once('value', (snap) => console.log(snap.val()));

Read the Firebase documentation for more details.