我正在努力删除其值(时间戳)在 2 小时后过去的文档。我必须调用 onSnapshot() 但不调用 snapshot.foreach() 。通过console.log检查; Called1 显示在控制台上,但 Called2 没有显示。我想知道为什么不调用它来删除文档。
onMounted(() => {
const itemsCollectionRef = collection(db, "Bookings");
const cutoffTimestamp = Date.now() - 2 * 60 * 60 * 1000; // Two hours ago
const oldItemsQuery = query(
itemsCollectionRef,
where("Date", "<", cutoffTimestamp)
);
onSnapshot(oldItemsQuery, (snapshot) => {
console.log('called1');
snapshot.forEach((doc) => {
// Delete the document
console.log('called2');
db.collection("Bookings").doc(doc.id).delete();
});
});
}) Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号