0
필드에서 가져 오는 Firestore 컬렉션 ("shows")에 필드 ("artistName")를 만들려고합니다. "이름")을 다른 Firestore 컬렉션 ("아티스트")에 저장합니다. "쇼"컬렉션에는 "아티스트"컬렉션의 문서를 가리키는 참조 필드 ("아티스트")가 있습니다. Google Cloud 기능을 사용하여 입력란을 만들려면 여기 내 코드는 다음과 같습니다.Google Cloud 함수를 사용하여 다른 Firestore 컬렉션에서 참조 된 필드에서 Firestore 컬렉션의 필드 만들기
exports.addReferenceDataToCollection = functions.firestore
.document('shows/{showId}').onWrite(event => {
var newValue = event.data.data();
var artistId = newValue.artist.id;
var artistRef = firestore.collection('artists').doc(artistId);
return event.data.ref.set({
artistName: artistRef.get().then(doc => {
if (!doc.exists) {
console.log('No such document!');
} else {
console.log('Document data:', doc.data());
var artistName = doc.data().name;
console.log('Artist Name:', artistName);
return Promise.resolve(artistName);
}
})
}, {merge: true});
});
나는 약속을 지키지 못하는 것 같습니다.