ref2.orderByChild 不是函数
ref2.orderByChild is not a function
一段时间后,我试图从 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 中存在数据,我只是将它们隐藏在这里
新的模块化 SDK 中有一个顶级函数 query()
可用于构建查询。同样,orderByChild()
等查询约束也是一个函数。尝试重构代码,如下所示:
var old = query(ref2, orderByChild('timestamp'), endAt(cutoff), limitToLast(1));
var listener = onChildAdded(old, function(snapshot) {
// ...
});
我看到你导入了“get”但没有使用它,
并且参考“/2021-2022/Pentamestre/Voti/Novità”可能是
"2021-2022/Pentamestre/Voti/Novità"
因为路径不是以 /slash 开头
一段时间后,我试图从 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 中存在数据,我只是将它们隐藏在这里
新的模块化 SDK 中有一个顶级函数 query()
可用于构建查询。同样,orderByChild()
等查询约束也是一个函数。尝试重构代码,如下所示:
var old = query(ref2, orderByChild('timestamp'), endAt(cutoff), limitToLast(1));
var listener = onChildAdded(old, function(snapshot) {
// ...
});
我看到你导入了“get”但没有使用它, 并且参考“/2021-2022/Pentamestre/Voti/Novità”可能是
"2021-2022/Pentamestre/Voti/Novità"
因为路径不是以 /slash 开头