简体   繁体   English

如何在 Firebase Web 应用程序中通过密钥(手机号码)获取数据?

[英]How To Get data by key (mobile number) in firebase web application?

I have record in User table in firebase and I want data by mobile number.我在 firebase 的 User 表中有记录,我想要手机号码的数据。 mobile number is primary key in user table .手机号码是用户表中的主键

I have code for getting data from table but in that code I am using loop so process taking time to get any one record from table.我有从表中获取数据的代码,但在该代码中我使用循环,因此处理需要时间从表中获取任何一条记录。 I have more then 3000 records in my users table.我的用户表中有 3000 多条记录。 anyone have idea that how can I get a single record by key in Firebase table using javascript or jquery?任何人都知道如何使用 javascript 或 jquery 在 Firebase 表中通过键获取单个记录?

[Here is my table Structure Image] [这是我的表结构图]

firebase.database().ref('users').child('1234567890').once('value').then( function(snap) {
    const user = snap.val()
    const userKey = snap.key
})

So using this, you can fetch the particular user you want.因此,使用它,您可以获取所需的特定用户。 snap.val() will give you user object and snap.key will give the key (in this case key = 1234567890). snap.val()将为您提供用户对象,而snap.key将提供密钥(在本例中为 key = 1234567890)。 This is the code for javascript.这是javascript的代码。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM