У меня есть эта архитектура в моем хранилище: test1 / {test1ID} / test2 /
Я хочу взаимодействовать с моим хранилищем в облачных функциях всякий раз, когда новые данные добавляются в test1ID.
My цель - обновить документ test1ID, в котором обновляются данные, со значением [0] th + [1] th + [2] th документ в подколлекции test2.
Но с приведенным ниже кодом я получаю документ test2 list (currentTest2DocumentList) undefined.
(сообщение об ошибке => TypeError: невозможно прочитать свойство '0' of undefined)
Как я могу получить действительный список документов в подколлекции?
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.onItemDocumentUpdate = functions.firestore.document('test1/{test1ID}')
.onUpdate(async (change, context) => {
const currentTest1ID = context.params.test1ID
const currentTest2DocumentList = await
admin.firestore().collection('test1').doc(currentTest1ID).collection('test2').get()
.then(function(docs) {return docs.forEach(function (doc){doc.data()})})
const addedValue = currentTest2DocumentList[0].field1 + currentTest2DocumentList[1].field1 +
currentTest2DocumentList[2].field1
return admin.firestore().collection('test1').doc(currentTest1ID).update({testField:
addedValue});