Querying array from Firebase (React Native) [duplicate]

*爱你&永不变心* 提交于 2021-01-29 09:00:13

问题


I'm new to react-native and firebase, and I am building an app. I stumble upon a problem using "array" in firebase (i know that firebase doesn't work with array), but I want to know if there is some way to retrieve this data.

This is the data I have in the server, and I want to get all the purchases that have the product "id" (in red)

I tried to use the code below and some variants but no success, returns null

firebase.database().ref('purchases').orderByChild("products/id")
.equalTo("-Lgida0VKuZZ6V7K0LkH").on('value', function (rawPurchases)

I want to know if there is a way to get this information.

Thanks.


回答1:


var scoresRef = firebase.database().ref("purchases");
scoresRef.orderByChild("products").on("value", function(snapshot) {
  snapshot.forEach(function(data) {
    console.log("The " + data.id + " data is " + data.val());
  });
});

try this method and review more here



来源:https://stackoverflow.com/questions/56659730/querying-array-from-firebase-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!