Swift 如何一次从以下用户检索帖子?
我想通过以下用户的ID检索帖子。我看过很多文章,但还没有找到解决办法。也许,我看的地方不对 数据库结构:Swift 如何一次从以下用户检索帖子?,swift,google-cloud-firestore,Swift,Google Cloud Firestore,我想通过以下用户的ID检索帖子。我看过很多文章,但还没有找到解决办法。也许,我看的地方不对 数据库结构: Firestore-root | --- users (collection) | | | --- uid (documents) | | | --- name: "User Name" | | | --- email: "email@email.com"
Firestore-root
|
--- users (collection)
| |
| --- uid (documents)
| |
| --- name: "User Name"
| |
| --- email: "email@email.com"
|
--- following (collection)
| |
| --- uid (document)
| |
| --- userFollowing (collection)
| |
| --- uid (documents)
| |
| --- uid (documents)
|
--- posts (collection)
|
--- uid (documents)
|
--- userPosts (collection)
|
--- postId (documents)
| |
| --- title: "Post Title"
| |
| --- date: September 03, 2018 at 6:16:58 PM UTC+3
|
--- postId (documents)
|
--- title: "Post Title"
|
--- date: September 03, 2018 at 6:16:58 PM UTC+3
用于检索帖子的函数:
static func subscribe(userID: String) -> AppThunkAction {
AppThunkAction { dispatch, _ in
let listener = Snapshot<Model.Photo>.listen(.photos(userID: userID), queryBuilderBlock: {
$0.order(by: .updateTime, descending: true).limit(to: 30)
}) { result in
switch result {
case let .success(photos):
dispatch(PhotosAction.updatePhotos(photos: photos))
case let .failure(error):
print(error)
// error handling
dispatch(PhotosAction.updatePhotos(photos: []))
}
}
dispatch(PhotosAction.updateListener(listener: listener))
}
}
static func subscribe(userID:String)->AppThunkAction{
AppThunkAction{调度,u中
让listener=Snapshot.listen(.photos(userID:userID),queryBuilderBlock:{
$0.订单(按:.updateTime,降序:true)。限制(至:30)
}){导致
切换结果{
成功案例(照片):
发送(PhotoAction.updatePhotos(照片:照片))
案例失败(错误):
打印(错误)
//错误处理
发送(PhotoAction.updatePhotos(照片:[]))
}
}
调度(PhotoAction.updateListener(侦听器:侦听器))
}
}
有一些方法可以实现这一点。您需要为每个用户获取uid
,并将其与帖子中的uid
进行比较。我建议你看看社区的帖子。这篇文章就如何实现这一点提供了一些想法
此外,官方文件还提供了Swift查询示例
下面的另外两篇文章应该为您提供一些关于使用Swift、per ID进行查询的额外见解
如果这些信息对你有帮助,请告诉我 它与swiftui有什么关系???确切地说是哪一部分?不确切地说是:(.也许,我不够好,无法理解。我不明白的一点是,我可以获得我关注的所有用户的ID。但是,我不知道如何一次通过这些ID查询帖子。通过我帖子中的上述查询,我只能查询一个用户。Hi@PeaceCloud有一些关于它的文档-就像这个和-你可以检查和这个v这篇文章非常好,提供了更多关于它的见解。你应该更好地理解对多个文档的查询。