我正在創建一個簡單的 Web 應用程式,并希望通過他們的 postId 一次獲取 10 個特定的帖子回復。
我正在使用 Firebase firestore,這是我的資料庫設計
posts/{postDocument}/replies/{replyDocument}.
這里的回復是一個集合內的檔案replies,其中包含一個檔案post
我的用例是我想一次獲取 10 個帖子,因此對于每個帖子還有它的子集合(回復)
如果我做一個回圈for each postDocumentId await fetchReplies(postDocumentId),一次迭代會花費太多時間(總共 10 次迭代)
我想實作這樣的目標:
let postIds = [ '123', '321', '221','123', '021', '621','423', '521', '291','251' ]
let snapshot = await firestore()
.collection('posts/replies')
.where('postId', 'in', postIds)
.get();
最后,我想以最佳方式從 firebase 獲取資料并以這種型別獲取:
[{post:{...},
replies:[{...},{...}]},
{post:{...},
replies:[{...},{...}]},
{post:{...},
replies:[{...},{...}]},
{post:{...},
replies:[{...},{...}]},
{post:{...},
replies:[{...},{...}]}]
先感謝您
uj5u.com熱心網友回復:
您可以replies使用集合組查詢從所有集合中讀取檔案。
但是沒有辦法將其限制為replies一組特定檔案 ID 下的集合,除非這些檔案 ID 也在replies檔案中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/322653.html
標籤:javascript 火力基地 谷歌云firestore
