Abu Zubair
Abu Zubair

Reputation: 128

Get parent uid data

I'm trying to get UID data.

Here are my Firebase database structure

enter image description here

and the rules

enter image description here

my code in .ts

firebase.database().ref('/appointment/').orderByChild('keys').equalTo(this.user.$key).once('value').then(snapshot => {
  snapshot.forEach(function(child) {
    console.log(child.key);
  });
})

but i got this in console

FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "keys" at /appointment to your security rules for better performance 

Please, any idea on what I am doing wrong?? how can i get the uid??

Upvotes: 1

Views: 255

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80914

You don't have a child called key in the database, this is what you have:

appointment
        userid
            randomKey
                 almt:...
                 gr:...

If you want to retrieve the current userid, then do this:

 var user = firebase.auth().currentUser;
 var uid=user.uid;

If you just want to retrieve it from the database, then do this:

firebase.database().ref('/appointment/').once('value').then(snapshot => {
snapshot.forEach(function(child) {
  console.log(child.key);
 });
})

This will loop inside the direct child of appointment and child.key will retrieve the uid

Upvotes: 1

Related Questions