【发布时间】:2021-05-09 10:30:09
【问题描述】:
更新
对于将来也遇到类似问题的任何人。我不确定为什么带有 documentWithPath 和 documentWithCollection 的 ObjectiveC-SDK 不起作用,但我发现如果我们直接给出它可以工作的路径。
所以不要问
self.db collectionWithPath:@"stage_tickets"]documentWithPath:bookingReference]collectionWithPath:@"tickets"]getDocumentsWithCompletion
一无所获,你可以直接写路径
self.db collectionWithPath:@"stage_tickets/{bookingReference}/tickets"]getDocumentsWithCompletion
我有一个类似这样结构的 Cloud FireStore 数据库。
结构基本上是stage_tickets(Collection)->Numbers(Documents)->Tickets(Collection)->Numbers(Documents)
真正奇怪的是,如果我想从第一级获取所有数字,我可以很容易地通过
[[self.db collectionWithPath:@"stage_tickets"]
getDocumentsWithCompletion:^(FIRQuerySnapshot *snapshot, NSError *error) {
if (error != nil) {
NSLog(@"Error getting documents: %@", error);
} else {
for (FIRDocumentSnapshot *document in snapshot.documents) {
NSLog(@"%@ => %@", document.documentID, document.data);
}
}
}];
但如果我尝试通过
达到第二级数字[[[[self.db collectionWithPath:@"stage_tickets"]documentWithPath:bookingReference]collectionWithPath:@"tickets"]getDocumentsWithCompletion:^(FIRQuerySnapshot * _Nullable snapshot, NSError * _Nullable error) {
if(error!=nil){
NSLog(@"error in getting QR Code");
}else{
for (FIRDocumentSnapshot *document in snapshot.documents) {
NSLog(@"%@ => %@", document.documentID, document.data);
}
}
}];
我得到的只是快照中的空文档。任何人都可以建议我在这里做错了什么,也许是我不知道的一些 fireStore 行为以及我该如何解决这个问题。
【问题讨论】:
-
你想从第一阶段获取stage_tickets(Collection)->Numbers(Documents)->Tickets(Collection)>Numbers(Documents)这个文件_stage_tickets(Collection)->Numbers(Documents)或者所有Tickets (收集)文件??
-
我基本上想从第二栏的门票集合中获取所有门票(文档/最后一栏)。
标签: ios objective-c swift firebase google-cloud-firestore