【发布时间】:2023-01-10 23:44:01
【问题描述】:
我正在尝试制作理发店网络应用程序,客户可以在其中查看免费约会列表,当他们预订免费约会时,我想从 firebase 中删除该字段。
我有一个代表一个理发师的集合。 这就是它在 Firebase 中的样子。
如您所见,radno_vrijeme 是 firebase 中的对象或映射,其中包含 6 个数组,每个数组中都有空闲工作时间列表。
在我的函数中,除了需要更新 firebase 集合的最后一行,我可以做所有事情。
const finishReservation = async () => {
try {
const freeTimeRef = collection(db, `${barber}`);
const q = query(freeTimeRef);
const querySnap = await getDoc(q);
querySnap.forEach(async (doc) => {
const radnoVrijeme = doc.data().radno_vrijeme;
// Find the index of the hour you want to delete
const index = radnoVrijeme["Mon"].indexOf(hour);
// Remove the hour from the array
radnoVrijeme["Mon"].splice(index, 1);
// Update the document in the collection
console.log(radnoVrijeme);
const radnoVrijemeMap = new Map(Object.entries(radnoVrijeme));
await freeTimeRef.update({ radno_vrijeme: radnoVrijemeMap });
});
} catch (error) {
console.log(error);
}
};
我试图将它作为 JSON 字符串化对象传递,但没有成功。我总是收到这个错误:
“FirebaseError:预期类型为‘ya’,但它是:自定义 Ia 对象”
【问题讨论】:
标签: javascript firebase google-cloud-firestore