2017-12-13 22 views
0

クラウドFirestoreのユーザーコレクションからcurrentUser(doc)を取得するために、適切な方法を除いてすべてを試しました。このようなVUE-firestoreとしてクラウドFirestore、現在のユーザーを取得

:結合

この$

( "ユーザー"、firebase.firestore()コレクション( "ユーザー")DOC(this.firebase.auth()CurrentUserに)。。。)

ご協力いただき、ありがとうございます。ユーザーがクラウドfirestoreで文書があるので、

答えて

0

、あなたはドキュメントからdocumentatin https://firebase.google.com/docs/firestore/query-data/get-data

応じて、このように単一のドキュメントを検索することができます: -

次の例では、取得する方法を示していますGETを使用して、単一の文書の内容():

var docRef = db.collection("cities").doc("SF"); 

docRef.get().then(function(doc) { 
    if (doc.exists) { 
     console.log("Document data:", doc.data()); 
    } else { 
     console.log("No such document!"); 
    } 
}).catch(function(error) { 
    console.log("Error getting document:", error); 
}); 

の場合、次の操作を行うことができます。 -

 const db = firebase.firestore() 

     db.collection('users') 
    .doc('currentUserID') // change to the current user id 
    .get().then((user)=>{ 
     if(user.exists){ 
      // now you can do something with user 
      console.log(user.data()) 
     } 
    }) 
0

ユーザーをコレクションから取得するには、サインインしたユーザーのUIDが必要です。 Auth()オブジェクトは、「Firestoreデータベーストリガー」ではまだ実装されていません。 (これはfirebase RTD用に実装されている)

ここに私の答えを参照してください:

Getting the user id from a Firestore Trigger in Cloud Functions for Firebase?

関連する問題