![](/img/trans.png)
[英]NodeJs function not working as expected in Firebase Cloud functions
[英]Firebase Functions: orderBy function not working
以下代碼在模擬器中工作,但當includeVideos
或includeAudios
為false
時在includeVideos
返回一個空數組:
let query = db.collection("content");
if (includeVideos && !includeAudios) {
query = query.where("type", '==', "video").orderBy("type");
}
if (includeAudios && !includeVideos) {
query = query.where("type", '==', "audio").orderBy("type");
}
if (!includeVideos && !includeAudios) {
return {empty json....}
}
if (matchingPersonID != undefined) {
query = query.where("attributionID", '==', matchingPersonID).orderBy("attributionID");
}
//either categories OR matchingSeriesID is always undefined/empty
if (matchingSeriesID != undefined) {
query = query.where("seriesIDs", 'array-contains', matchingSeriesID).orderBy("seriesIDs");
}
if (matchingCategories.length != 0) {
// 'OR' LOGIC
query = query.where("categories", 'array-contains-any', matchingCategories).orderBy("categories");
}
if (lastDocumentID != undefined) {
await db.collection("content").doc(lastDocumentID).get().then((snapshot) => {
query = query.startAfter(snapshot);
log(`starting after document ${snapshot}`)
})
}
//the code works when this line is removed, but the query needs to be sorted by time in order for pagination to work
query = query.orderBy("upload_date", "desc");
return query.limit(getNext).get()...
我在谷歌雲日志中沒有收到錯誤消息,所以我沒有簡單的方法來創建索引,如果這是我需要做的。 在 firestore 中,字段upload_date
、 attributionID
、 type
、 seriesIDs
和categories
都在文檔中的同一級別。
任何幫助將非常感激!!
當您發表評論時,似乎缺少該字段的索引。
本文檔提到了兩種處理這些索引的方法:
通過使用 CLI。 您可以將索引放入 JSON 格式的本地文件中。 為此,在您的 firebase 項目文件夾中運行firebase firestore:indexes
,您將獲得一個格式化的 JSON 輸出供您復制,添加一個新輸出,然后firebase deploy --only firestore:indexes
部署它們。
實際上,當 Firebase 捕獲到使用不存在的索引的錯誤時,您可以使用它生成的 URL,但您也可以從應用程序的 Firebase 控制台手動執行此操作:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.