我最近開發了一個 firebase schedule 函式來檢索每個星期一的資料。我在前幾天測驗過它,它作業正常。然而,今天早上,我發現我的查詢不能再像以前那樣檢索資料了。我現在在 QuerySnapshot.docs 中有一個空陣列。你可以在下面找到我的代碼:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const db = admin.firestore();
exports.scheduledFunction = functions.pubsub.schedule("0 0 * * 1").onRun(async () => {
console.log("start");
const querySnapshotnext = await db.collection("Next_challenges").orderBy("createdAt").get();
console.log("Let see querySnapshot :", querySnapshotnext); //it works, I can see QuerySnapshot object
console.log("Let see docs :", querySnapshotnext.docs); //have an empty array [] even if it should not, it wasn't empty few days ago
console.log("let see the data of the first doc : ", querySnapshotnext.docs[0].data()); //is of course undefined
return null;
});
您可以使用通常選擇的檔案在下面找到我的資料庫:

我的資料庫規則如下:

我真的不明白為什么我的代碼不再作業了,我認為它肯定與某些引數有關,并且我真的不知道如何自己除錯它,所以請不要猶豫給我一些提示,以便我可以使用 firebase 更加自主。謝謝 :)
uj5u.com熱心網友回復:
Firestore 的檔案有一個注釋說,
orderBy() 子句還過濾給定欄位的存在。結果集將不包括不包含給定欄位的檔案。
您有.orderBy("createdAt")查詢,但createdAt檔案中沒有任何欄位(至少是螢屏截圖中的欄位)。您最近是否更改了導致此問題的檔案結構?
此外,Admin SDK 會繞過任何安全規則,因此如果您不需要直接從客戶端訪問資料,我建議將它們設定為 false。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/395204.html
標籤:javascript 火力基地 谷歌云firestore
