长期阅读者的首次发布者-一个很棒的社区。 p>
我正在学习Firestore / React,希望您能为此提供帮助-我正在拔头发!
谢谢!
欢呼 亚历克斯
数据结构如下:
contracts
service
linkedContractUid: [x, y, z]
linkedContractData: {contractId:{label: data, label: data, label: data}, contractId:{}, contractId:{}}
代码如下:
const updateServiceContract = (contract, contractId) => {
const updateDocs = admin.firestore().collection('service').where('linkedContractUid', 'array-contains', contractId)
var transaction = admin.firestore().runTransaction(t => {
return t.get(updateDocs)
.then(snapshot => {
snapshot.forEach(doc => {
const docRef = admin.firestore().collection('service').doc(doc.id)
console.log(docRef)
t.set(docRef, {
linkedContractData: {
[contractId]: contract
}
});
})
})
})
}
exports.contractUpdated = functions.firestore
.document('contracts/{contractId}')
.onUpdate((change, context) => {
const contract = change.after.data();
const contractId = change.after.id
return updateServiceContract(contract, contractId)
})