2017-12-11 16 views
0

により財産を取得し、私はFirebaseにこのデータベースを持っている:Firebaseは、電子メール

{ 
    "issues" : { 
    "-L04771_EjrLlv5u1-GU" : { 
     "issue" : "Test insert 1", 
     "last_edit" : "d8QICgTG5xR20RBzAXfzfu8gLgw2", 
     "owner" : "d8QICgTG5xR20RBzAXfzfu8gLgw2", 
     "owner_email" : "[email protected]", 
     "status" : 1, 
     "url" : "http://www.example.com/example.html" 
    }, 
    "-L047pIoqxkj4saaTYyQ" : { 
     "issue" : "Test insert 2", 
     "last_edit" : "d8QICgTG5xR20RBzAXfzfu8gLgw2", 
     "owner" : "d8QICgTG5xR20RBzAXfzfu8gLgw2", 
     "owner_email" : "[email protected]", 
     "status" : 1, 
     "url" : "http://www.example.com/example.html" 
    } 
    } 
} 

私は唯一の「[email protected]」OWNER_EMAIL持っている人を抽出する必要があります。

が可能ですか?

答えて

2

おそらくFirebase Queries、特にequalTo -Queryがあります。

あなたのコードは次のようになります。

// Find all issues with owner_email = [email protected] 
var ref = firebase.database().ref("issues"); 
ref.orderByChild("owner_email").equalTo("[email protected]").on("value", function(snapshot) { 
    // Loops through the matching issues 
    snapshot.forEach(function(child) { 
     console.log(child.key); 
    }); 
}); 
+1

コードは 'issues'を記録します。結果をループして、子キーを出力したいでしょう: 'snapshot.forEach(function(child){console.log(child.key);})' –

+0

正しいです。私はここで重要な部分であると私は思っています。私は私の答えを編集しました。言及いただきありがとうございます! – Frede

関連する問題