1

アプリでユーザーを認証した後、firestoreのuserProfileコレクションにユーザープロファイルドキュメントを作成するクラウド機能を作成します。firestoreでクラウド機能を使用してドキュメントを作成する

これは私がUSERPROFILEと呼ばれるコレクションを持っているfirestoreクラウドデータベースで

TypeError: admin.firestore(...).ref is not a function 
    at exports.createProfile.functions.auth.user.onCreate.event (/user_code/index.js:13:30) 
    at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:59:27) 
    at next (native) 
    at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71 
    at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12) 
    at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:53:36) 
    at /var/tmp/worker/worker.js:695:26 
    at process._tickDomainCallback (internal/process/next_tick.js:135:7) 

をエラー受け付けておりますされ、クラウド機能ここで

// 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); 

//function that triggers on user creation 
//this function will create a user profile in firestore database 
exports.createProfile = functions.auth.user().onCreate(event => { 
    // Do something after a new user account is created 
    return admin.firestore().ref(`/userProfile/${event.data.uid}`).set({ 
     email: event.data.email 
    }); 
}); 

のための私の全体のindex.jsファイルです

+0

よく見えます。 –

+0

私はこのエラーを取得しようとしますadmin.firestore()。refは関数ではありません –

+0

ファイル全体とエラー全体を表示できますか? –

答えて

1

admin.firestore()は、のインスタンスを返します。オブジェクト。 APIドキュメントからわかるように、Firestoreクラスにはref()メソッドはありません。おそらく、それをRealtime Database APIと混同しているでしょう。

Firestoreでは、コレクション内のドキュメントを整理する必要があります。文書に到達するには、この操作を行うことができます:ここで

const doc = admin.firestore().doc(`/userProfile/${event.data.uid}`) 

は、docDocumentReferenceです。次に、このようにその文書の内容を設定することができます。

doc.set({ email: event.data.email }) 

はFirestoreを設定する方法を理解するためにFirestore documentationを必ずお読みください - それはリアルタイムのデータベースとは異なるのです多くの場所があります。

関連する問題