0

I am batteling to find any data when I perform this query on the data.

the data struct is as follows:

users:
       id_123 : 
                name: "name a"
                surname: "surname a"
       id_124 : 
                name: "name b"
                surname: "surname b" 

-

// Find user by id
FIRDatabaseReference *ref = [[FIRDatabase database] referenceWithPath:@"users"];
FIRDatabaseQuery *qry = [ref queryEqualToValue:@"id_123"];

[qry observeEventType:FIRDataEventTypeChildAdded
            withBlock:^(FIRDataSnapshot *snapshot) {

                // THE DEBUGGER NEVER GETS HERE...
                NSLog(@"snapshot: %@", snapshot);

                NSDictionary *user = [snapshot value]; 

                //get user details:
                NSString *name = [user valueForKey:@"name"];
                NSString *surname = [user valueForKey:@"surname"];

}];
KENdi
  • 7,576
  • 2
  • 16
  • 31
Wayne
  • 3,359
  • 3
  • 30
  • 50

1 Answers1

1

It looks like you're just trying to read a child node.

FIRDatabaseReference *ref = [[FIRDatabase database] referenceWithPath:@"users"];
FIRDatabaseReference *user = [ref child:@"id_123"];

[user observeEventType:FIRDataEventTypeValue

Queries "skip a level", so you'd only need a query if you want to filter name or surname.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Great thanks for the help. Worked 100%, one strange thing though. The event fires twice , once for name and once more for surname. – Wayne Jul 11 '17 at 17:27
  • Oops.... the `ChildAdded` was a remnant from the query. You should use `Value` events for this. I updated the code. – Frank van Puffelen Jul 11 '17 at 19:14
  • Hi Frank, is it possible to do wild card queries? Say I want to find all records that have id's in a certain range, e.g child[@"id_12%"] – Wayne Jul 12 '17 at 09:21
  • Yes, you can get all keys starting with `id_12`. But in [your new question](https://stackoverflow.com/questions/45054550/firebase-database-how-to-perform-a-prefix-wildcard-query) you asked something slightly different. – Frank van Puffelen Jul 12 '17 at 14:05