0

I want to get the data under machine and the path is like this Users then Mobile Number then Machine and i want to get the child of the machine then match that data from the localstore if both match i want to print the child of mobile number. My data structure is like this.If anyone know please help

Users{
  +911234567890{
    "Name": "XYZ"
    "EmailId": "xyz@gmail.com"
    "Address": "abc"
    Machine{
      7D8721210004
      7D8721210005  //I Want to go here to match this with my localstore data. and                
                    // Print the details undert this(+911234567890) number.
    }
  }
}

and this is how i try.

var db = app.database();
var serial = localStorage.getItem('machineid')
db.ref("/Users/").child("/").child("Machines").child(serial).on("value", (snapshot)=>{
  console.log(snapshot.val())
})
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
MOHAMMAD ZEESHAN
  • 273
  • 3
  • 15
  • Hi, how about you try the path as mentioned in the example in the [document](https://firebase.google.com/docs/database/admin/retrieve-data#section-start) instead of using child? – Zeenath S N Dec 31 '21 at 12:39
  • 1
    The Firebase Realtime Database and Cloud Firestore are two separate databases. Please only mark your question with the relevant tag, not with both. – Frank van Puffelen Dec 31 '21 at 16:57
  • 1
    The data structure you have makes it easy to find the machines for a specific user/phone number. It does not however make it easy to find the user(s) for a given machine. To allow that you'll need to add an addition, inverted data structure that starts with the machine IDs, and then contains the UID(s) for each of those. See the questions I linked for more info and examples. – Frank van Puffelen Dec 31 '21 at 17:00
  • Thankyou @FrankvanPuffelen for the information – MOHAMMAD ZEESHAN Jan 03 '22 at 06:28

0 Answers0