Я пытаюсь выполнить пакетную фиксацию, но когда оба запроса возвращают что-то, я получаю сообщение об ошибке Невозможно изменить зафиксированный пакет WriteBatch. как мне решить эту проблему? может ли кто-нибудь предложить какое-либо решение для этого, это инициализация двух массивов и pu sh batch.commit (), а затем разрешение обещания
module.exports = async (change) => {
try {
const timerSnapshot = change.before.data().timestamp;
console.log(timerSnapshot, "before");
const timerTimestampMinusOne = momentTz(timerSnapshot)
.tz("Asia/Kolkata")
.subtract(1, "days")
.valueOf();
const timerMinusThreeHours = momentTz(timerSnapshot)
.tz("Asia/Kolkata")
.subtract(3, "hours")
.valueOf();
const [profileSnapshot, threeHourReminder] = await Promise.all([
db
.collection("Profiles")
.where("lastQueryFrom", ">", timerTimestampMinusOne)
.get(),
db
.collection("Profiles")
.where("lastQueryFrom", ">", timerMinusThreeHours)
.get(),
]);
const batch = db.batch();
const batchArray = [];
console.log(profileSnapshot.docs.length, "profile");
console.log(threeHourReminder.docs.length, "three");
profileSnapshot.forEach((doc) => {
batch.set(
db.collection("Timers").doc(getISO8601Date()),
{
timestamp: momentTz().tz("Asia/Kolkata").valueOf(),
},
{ merge: true }
);
batchArray.push(batch.commit());
});
threeHourReminder.forEach((doc) => {
batch.set(
db.collection("Timers").doc(getISO8601Date()),
{
timestamp: momentTz().tz("Asia/Kolkata").valueOf(),
},
{ merge: true }
);
batchArray.push(batch.commit());
});
await Promise.all(batchArray);
} catch (error) {
console.error(error);
}
};