// The Cloud Functions for Firebase SDK to create Cloud Functions and
setup triggers.
const functions = require('firebase-functions');
// The Firebase Admin SDK to access the Firebase Realtime Database.
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.giveCard = functions.firestore
.document('Profiles/{profileId}/cards/{cardsId}/_given/{_givenID}')
.onWrite((event) => {
// Get the field values of what I am working with
const oldGiven = event.data.previous.data()['given'];
const newGiven = event.data.data()['given'];
// Get the cardID to make sure that is there
const cardID = event.params.cardsId;
// An array to go through
const give_profiles = event.data.data()['given_profiles'];
// error cardDatatwo is returned as undefined
const cardDatatwo = newGiven.parent;
// error cardDatathree is returned as undefined
const cardDatathree = event.data.ref.root
// // error cardDatafour cannot read propoerty of undefined
// const cardDatafour = cardDatathree.child('Profiles/{profileId}/cards/{cardsId}')
// error cardDatafive 'The value of cardfive is DocumentReference...
const cardDatafive = event.data.ref.firestore.doc('Profiles/{profileId}/cards/{cardsId}');
// Check that the values have changed
if (newGiven == oldGiven) return;
if (newGiven !== undefined) {
console.log('The old value of given is', oldGiven);
console.log('The new value of given is', newGiven);
console.log('The value of the card is', cardID);
console.log('The value of the cardtwo is', cardDatatwo);
console.log('The value of the cardthree is', cardDatathree);
// console.log('The value of the cardfour is', cardDatafour);
console.log('The value of the cardfive is', cardDatafive);
for (var profile of give_profiles) {
console.log(profile);
};
return;
}
return console.log("No given value");
});
Cloudstore가 클라우드 기능을 사용하여 루트 권한을 얻는 데 큰 어려움을 겪고 있습니다. 그것은 다르게 작동합니다.클라우드 기능 및 Firestore가 Firebase의 루트가되지 않습니다.
onUpdate가 더 내려간 후 루트 경로를 따라 값을 얻으려고합니다.
.parent 또한 노드 및 event.data.ref.firestore 작동하지 않습니다) 즉 실시간 데이터베이스 의대로 작동하지 않습니다 물론 functions.database.ref을 작동하지 않고 firebase.firestore을 (사용할 수 없습니다 .doc가 정의되지 않은 상태로 돌아옵니다.
나는 모든 옵션을 선택했음을 확신합니다.
희망 하시겠습니까?
당신이 가지고있는 거리와 부모를 구현해야하는 위치를 보여주는 코드를 공유 할 수 있습니까? 이것이 DocumentSnapshot을 사용하는 청취자 콜백 내부에 있을까요? – Grimthorr
코드를 보여주고 파이어 스토어 API를 사용하려면 firebase-admin 모듈을 최신 버전으로 업데이트해야한다는 것을 기억하십시오. 답장은 –