Querying for existing nodes in Firebase is returning null

后端 未结 1 387
南旧
南旧 2021-01-20 06:39

My tree structure looks like in FireBase

  • BOOKS
  • USERS
    • UserA_ID
    • UserB_ID
    • UserC_ID
      • UserName:@\"\"
      • UserEmai
1条回答
  •  伪装坚强ぢ
    2021-01-20 07:08

    A couple of things. To test for null you should really

     if (snapshot.value == [NSNull null])
    

    Here's a slightly modified implementation of your code that includes the NSNull check.

    Firebase *ref = [self.myRootRef childByAppendingPath:@"users"];
    
    FQuery *query = [[ref queryOrderedByKey] queryEqualToValue:@"UserC_ID"];
    
        [query observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
    
            if (snapshot.value == [NSNull null]) {
                NSLog(@"was null");
            } else {
                NSLog(@"key: %@    %@", snapshot.key, snapshot.value);
            }
        }];
    

    I set up a test Firebase with the same structure you are using and it works correctly; returns null for nonexistent user id's and returns the node UserC_ID when it does.

    So maybe your code that sets the userIDKey is misbehaving or perhaps your userRef is wonky.

    0 讨论(0)
提交回复
热议问题