0

This is my Firebase Structure:

enter image description here

All the Child Nodes are added with childByAutoId. I want to get the record Where

Mode: "Paid"
Status: "Married"

Currently I am only able to get the list of all the nodes inside UserInfo

 [[_ref child:@"UserInfo"] observeSingleEventOfType:FIRDataEventTypeValue    withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
    // Get user value

  NSDictionary<NSString *, NSString *> *users = snapshot.value;

    NSError *error;


    NSLog(@"dict is %@",users);

 }
   withCancelBlock:^(NSError * _Nonnull error)
 {

     NSLog(@"%@", error.localizedDescription);
 }];
Saad Chaudhry
  • 1,392
  • 23
  • 37
  • Firebase dB has a flat structure. Unfortunately you can't apply where clause on more than one attributes. You have to make some structural changes to do that and you'll have to manage all the database transactions yourself unlike SQL databases where you can take advantage of the already available rules like cascade, restrict etc. – Adeel Miraj Feb 19 '17 at 13:14
  • Adeel, so if a person wants to apply some filters he/she have to apply it locally. Any proposed structural changes will be appreciated. – Saad Chaudhry Feb 19 '17 at 15:29
  • And if I want to apply this on a single attribute like select all where status is married can you give me some idea how to achieve that. – Saad Chaudhry Feb 19 '17 at 15:30
  • In this (and many other cases) you can combine the values you want to order/filter on into a single property, e.g. `mode_status: "Paid_Married"` and filter on that. See my answer here for more: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase. For more on the syntax of filtering in iOS, see: https://firebase.google.com/docs/database/ios/lists-of-data#filtering_data or [previous answers](http://stackoverflow.com/search?q=%5Bfirebase-database%5D%5Bobjective-c%5D+filter) – Frank van Puffelen Feb 19 '17 at 16:10

0 Answers0