0

The childByAutoId would be useful if you want to save in a node multiple children of the same type, that way each children will have its own unique identifier.

pet:{
    KJHBJJHB:{
      name:fluffy,
      owner:John Smith,
    },
    KhBHJBJjJ:{
      name:fluffy,
      owner:Jane Foster,
    }
} 

Therefore, once I have that uID, and I want to retrieve an specific user using the his/her uID. How do I tell Firebase that I want that specific user? Because I create it and store it in Firebase, but then to read it, don't I need to know the value of the uID? Where do I get it from?

What function do I use to retrieve for example the second user using the uID?

Thanks in advance..

Jorge A Gomez
  • 473
  • 6
  • 15
  • the title doesn't match the body.... you don't care about the value of the uid but you want to filter out all children where owner = XY instead right? – Daij-Djan Jun 09 '16 at 21:15
  • I need to filter just one specific user. What I am trying to do is that when a user is selected from a tableView to udpate the profile information, I need to retrieve all information from that specific user and update it. But how can I get the path of that specific user if the path includes the key? if I want to reach that specific user I need to get that key again right? So that I can query using the unique ID – Jorge A Gomez Jun 14 '16 at 22:30

1 Answers1

1

in the title u ask how to get rid so:: get the new ref's key property to get the aid created

FIRDatabaseReference *ref = parent.childByAutoID
NSString *uid = ref.key

BUT thats not what you want id say, so:

to filter out all children where owner = XY which you want I think:

FIRDatabaseReference *ref = your pets node 
FIRDatabaseQuery *allPets = [ref queryOrderedByChild:@"owner"];
FIRDatabaseQuery *specificPet = [allPets queryEqualToValue:@"XY"];

[specificPet observeEventType:FEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot) {
  NSDictionary *dict = snapshot.value;
  NSString *key = snapshot.key;

  NSLog(@"key = %@ for child %@", key, dict);
}];

see: Query users by name or email address using Firebase (Swift)

Community
  • 1
  • 1
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135