我試圖在一段時間后從firebase實時資料庫中洗掉一些資料,但給了我這個錯誤:Uncaught TypeError: ref2.orderByChild is not a function
這是代碼:
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-app.js";
import {getDatabase, ref, child, onValue, get} from "https://www.gstatic.com/firebasejs/9.8.1/firebase-database.js"
import "https://cdn.jsdelivr.net/npm/seamless-scroll-polyfill@latest/lib/bundle.min.js";
const firebaseConfig = {
apiKey: "xxxxx",
authDomain: "xxxxx",
databaseURL: "xxxxx",
projectId: "xxxxx",
storageBucket: "xxxxx",
messagingSenderId: "xxxxx",
appId: "xxxxx"
};
const app = initializeApp(firebaseConfig);
const db = getDatabase();
var ref2 = ref(db, "/2021-2022/Pentamestre/Voti/Novità");
var now = Date.now();
var cutoff = now - 2 * 60 * 60 * 1000;
var old = ref2.orderByChild('timestamp').endAt(cutoff).limitToLast(1);
var listener = old.on('child_added', function(snapshot) {
snapshot.ref.remove();
});
顯然在firebaseConfig中資料是存在的,我只在這里隱藏它們
uj5u.com熱心網友回復:
新的模塊化 SDK 中有一個頂級函式query()來構建查詢。同樣,orderByChild()其他查詢約束也是一個函式。嘗試重構代碼,如下所示:
var old = query(ref2, orderByChild('timestamp'), endAt(cutoff), limitToLast(1));
var listener = onChildAdded(old, function(snapshot) {
// ...
});
uj5u.com熱心網友回復:
我看到您匯入了“get”但沒有使用它,并且參考“/2021-2022/Pentamestre/Voti/Novità”可能是
"2021-2022/Pentamestre/Voti/Novità"
因為路徑不以 /slash 開頭
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/475469.html
標籤:javascript 火力基地 firebase-实时数据库
上一篇:使用云功能添加時,firebase時間戳物件在每個鍵之前接收一個_?
下一篇:新資料庫條目時創建新產品頁面
