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 파일입니다 어디에 인증 후에 사용자에게 부여 된 고유 ID로 문서를 작성해야합니다.

+0

좋아 보인다. –

+0

이 오류가 발생하면 admin.firestore()를 참조하십시오. ref는 함수가 아닙니다. –

+0

전체 코드 파일과 전체 오류를 표시 할 수 있습니까? –

답변

1

admin.firestore()Firestore 개체. Firestore 클래스에는 API 문서에서 볼 수 있듯이 ref() 메소드가 없습니다. 아마도 실시간 데이터베이스 API와 혼동스러워 할 것입니다.

Firestore에서는 컬렉션 내의 문서를 구성해야합니다. 문서에 도달하기 위해, 당신이 할 수 있습니다 : 여기

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

docDocumentReference이다. 당신은 다음과 같이 해당 문서의 내용을 설정할 수 있습니다

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

는 경우 FireStore를 설정하는 방법을 이해하는 경우 FireStore documentation을 읽어 보시기 바랍니다 - 그것은 실시간 데이터베이스와 다른의 많은 장소가있다.

관련 문제