2016-03-04 176 views
0

我在我的應用中使用了Firebase,並且我有一個路徑,其中包含'linked_timestamp'值爲kFirebaseServerValueTimestamp的子節點。我使用此代碼只返回不超過24小時的項目:Firebase查詢返回奇怪結果

Firebase *usersRef = [[Firebase alloc] initWithUrl:@"https://<MY-APP>.firebaseio.com/users"]; 
Firebase *itemsRef = [usersRef childByAppendingPath:[NSString stringWithFormat:@"/%@/items/", userId]]; 

double currentTimeSince1970 = (double)[[NSDate date] timeIntervalSince1970]; 
double epochTime = currentTimeSince1970 * 1000; 
double startingAtTimestamp = epochTime - (24 * 3600000); 
NSNumber *startingAtTimestampNumber = [[NSNumber alloc] initWithDouble:startingAtTimestamp]; 

FQuery *itemsQuery = [[itemsRef queryOrderedByChild:@"linked_timestamp"] queryStartingAtValue:startingAtTimestampNumber]; 
[itemsQuery observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) { 
    // Downloaded 
}]; 

但由於某些原因,有辦法一個子節點也將返回價值不大。

enter image description here

爲什麼任何想法?

更新

火力地堡結構:

{ 
"items" : { 
"-KBOcj7jlWh4wg8WWhyc" : { 
    // information 
    }, 
"-KBOcxL4f2-Az4meOLsW" : { 
    // information 
    } 
}, 
"users" : { 
"1117555594922215" : { 
    "first_name" : "First name", 
    "last_name" : "Last name", 
    "items" : { 
    "-KBOcj7jlWh4wg8WWhyc" : { 
     "linked_timestamp" : "54354" 
    }, 
    "-KBOcxL4f2-Az4meOLsW" : { 
     "linked_timestamp" : 1457119545959 
    } 
    }, 
    "register_date" : "04-03-2016 18:02" 
     } 
    } 
} 
+0

您是否可以將實際的Firebase數據結構複製/粘貼到您的問題中?您可以使用儀表板右上角的導出按鈕將其導出爲平面文件。 – Jay

+0

@Jay粘貼它現在,它有點從原來的結構剝離下來,不破壞應用程序的想法或顯示噸行 - 但它顯示在問題的查詢 – Erik

+0

好用的結構和數據。好。它正在做你在問什麼。如果您在Firebase中擁有54354個值,那麼您的Firebase查詢將返回該值。在我看來,有*寫*值的問題。 – Jay

回答

0

答案是,你的54354被存儲爲而不是數字。

我犯了這個錯誤很多次。

如果您進入Firebase儀表板,則可以單擊54354字段,它將具有圍繞數字「54354」的paren。刪除這些和你的代碼將工作。