嗨,我正在使用云函数将在子集合上创建的数据聚合到父集合,当我对其进行测试时,它就像一个超级按钮,但是当我将其部署到生产环境时,有时(并不常见)但发生)数据没有聚合到父文档中。
我认为该函数未执行,因为我在日志中没有收到任何错误。
这是我的功能代码
exports.aggregateTranlationsToSong = functions.firestore
.document("songs2/{songId}/translations/{langId}")
.onCreate((event, context) => {
const { songId, langId } = context.params;
console.log({ songId, langId });
let songRef = admin
.firestore()
.collection("songs2")
.doc(songId);
return admin
.firestore()
.runTransaction(transaction => {
return transaction.get(songRef).then(songSnap => {
let actualSongData = songSnap.data();
let translations = actualSongData.lyric_translations;
if (translations === undefined || translations === null)
translations = {};
translations[langId] = true;
console.log({ translations });
return transaction.update(songRef, {
lyric_translations: translations
});
});
})
.catch(e => {
console.error(e);
});
});