在Firebase函数中过滤数据 [英] Filter data in Firebase Functions
本文介绍了在Firebase函数中过滤数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何查找具有myPhone值= 123的users.key值
how can I find the users.key value that has myPhone with value = 123
我尝试过的事情:
let usersRef = admin.database().ref("users");
usersRef
.orderByChild("myPhone")
.equalTo("123")
.on('value', function(snapshot) {
console.log("Snapshot "+ snapshot.val() );
});
推荐答案
您正在过滤字符串,但正在存储数字.要使其起作用:
You're filtering on a string, but are storing a number. To make it work:
let usersRef = admin.database().ref("users");
usersRef.orderByChild("myPhone")
.equalTo(123)
.on('value', function(snapshot) {
snapshot.forEach((userSnapshot) {
console.log("User "+userSnapshot.key+": "+ userSnapshot.val() );
});
});
尽管我可能会建议实际上将电话号码存储为字符串.
Although I'd probably recommend actually storing the phone number as a string.
这篇关于在Firebase函数中过滤数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文