【发布时间】:2016-02-18 16:10:57
【问题描述】:
我的树形结构看起来像 FireBase 中的
- 书籍
- 用户
- 用户A_ID
- 用户B_ID
- 用户C_ID
- 用户名:@""
- 用户邮箱:@""
- UserBookReadCount:@""
在我去更新“BookReadCount”之前,我尝试使用以下代码查询该用户的存在。在
FQuery* query = [[userRef queryOrderedByKey] queryEqualToValue:userIDKey];
[query observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot)
{
NSLog(@"Snapshot value: %@", snapshot.value);
if(snapshot.hasChildren)
{
// UserX_ID exists. Use 'updateChildValues' to update the data
}
else
{
// UserX_ID does NOT exist. Use 'setValue' to create the data
}
}];
如果用户不存在,我会使用“setValue”将新用户添加到此列表中。如果用户存在,那么我使用“updateChildValues”来更新用户数据。所有这一切都很好。
我面临的问题是查询。即使用户存在或不存在,上面的查询也总是返回null。
对我遗漏的显而易见的事情有什么想法吗?
【问题讨论】: