// 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");
});
Firestoreがクラウド機能で動作するためのルートを取得するのが非常に困難です。それはもちろん、異なって動作します。クラウドファンクションとFirestoreがFirebaseのルートになっていない
私は、さらに更新されたonUpdateが実行された後、ルートに向かってパスを取得しようとしています。
.parentはもちろんの functions.database.refは、それがリアルタイムデータベース だと動作しないと( firebase.firestoreを使用することはできません動作しませんが)また、ノード とevent.data.ref.firestoreに動作していません.docは定義されていません。
私は確かにすべてのオプションを通過しました。
希望すると助かります。
あなたはどこまで持っていて、どこに 'parent'を実装する必要があるかを示すコードをいくつか共有できますか?これは 'DocumentSnapshot'のリスナーコールバック内にあるでしょうか? – Grimthorr
Firestore APIを使用できるようにするには、コードを示してください。また、firebase-adminモジュールを最新バージョンに更新する必要があります。返信の場合は –