0

This is my code

firebase.database().ref().child('Users').orderByChild('interest').
startAt('cat').endAt('cat'+'\uf8ff').
on('value',snap=>{
  console.log(snap.val())
})

my database

my code is that way but result is return null , How can I access data?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Ahmet Saz
  • 61
  • 5
  • The child `interest` doesn't have a string value, so no child nodes match the `startAt` and `endAt` criteria. The Firebase query language does not allow filtering array value like that. So while your current data structure is great for efficiently loading the interests for a specific user, it does not allow efficient loading of the users for a specific interest. For that you'll want to add a so-called inverted data structure: `/Interests/$interest` with the user IDs of the users who have that interest. Also see my answer in: https://stackoverflow.com/q/40656589/ – Frank van Puffelen May 21 '18 at 14:31

1 Answers1

0

get methods:

getUsers() {
 firebase.database().ref('Users')
  .once('value')        
  .then(snapshot => snapshot.val())    
  .then(users => console.log(users));
}
Gurbela
  • 1,184
  • 2
  • 16
  • 40