Firebase查询返回奇怪结果
问题描述:
我在我的应用中使用了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
}];
但由于某些原因,有办法一个子节点也将返回价值不大。
为什么任何想法?
更新
火力地堡结构:
{
"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"
}
}
}
答
答案是,你的54354被存储为串而不是数字。
我犯了这个错误很多次。
如果您进入Firebase仪表板,则可以单击54354字段,它将具有围绕数字“54354”的paren。删除这些和你的代码将工作。
您是否可以将实际的Firebase数据结构复制/粘贴到您的问题中?您可以使用仪表板右上角的导出按钮将其导出为平面文件。 – Jay
@Jay粘贴它现在,它有点从原来的结构剥离下来,不破坏应用程序的想法或显示吨行 - 但它显示在问题的查询 – Erik
好用的结构和数据。好。它正在做你在问什么。如果您在Firebase中拥有54354个值,那么您的Firebase查询将返回该值。在我看来,有*写*值的问题。 – Jay