Your code crashes because you are receiving a child from a user uidwho does not actually exist. K2xxxxxxxx- This is a unique string for each item and does not match the user ID. try it
_ref = [[FIRDatabase database] reference];
_hotelRef = [_ref child:@"hotel bookings"];
FIRDatabaseQuery *userHotelBookingsQuery = [_hotelRef queryOrderedByChild:@"number"];
[userHotelBookingsQuery observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
if (snapshot.value == [NSNull null]) {
NSLog(@"No messages");
} else {
NSDictionary *allUsersData = (NSDictionary*)snapshot.value;
for (NSString *key in allUsersData.allKeys) {
NSLog("@key is %@, data is %@",key,allUsersData[key]);
}
}
}];
}
Edit:
-
FIRDatabaseQuery *userHotelBookingsQuery = [[_hotelRef queryOrderedByChild:@"userID"] queryEqualToValue:@"GEmxxxxxxxxx"];