Firebase,通过电子邮件获取财产

时间:2017-12-11 10:38:22

标签: firebase-realtime-database

我在Firebase上有这个数据库:

{
  "issues" : {
    "-L04771_EjrLlv5u1-GU" : {
      "issue" : "Test insert 1",
      "last_edit" : "d8QICgTG5xR20RBzAXfzfu8gLgw2",
      "owner" : "d8QICgTG5xR20RBzAXfzfu8gLgw2",
      "owner_email" : "example1@gmail.com",
      "status" : 1,
      "url" : "http://www.example.com/example.html"
    },
    "-L047pIoqxkj4saaTYyQ" : {
      "issue" : "Test insert 2",
      "last_edit" : "d8QICgTG5xR20RBzAXfzfu8gLgw2",
      "owner" : "d8QICgTG5xR20RBzAXfzfu8gLgw2",
      "owner_email" : "example2@gmail.com",
      "status" : 1,
      "url" : "http://www.example.com/example.html"
    }
  }
}

我必须只提取拥有owner_email“example1@gmail.com”的人。

有可能吗?

1 个答案:

答案 0 :(得分:2)

您可能正在寻找Firebase Queries,尤其是equalTo - 查询。

您的代码将是这样的:

// Find all issues with owner_email = example1@gmail.com
var ref = firebase.database().ref("issues");
ref.orderByChild("owner_email").equalTo("example1@gmail.com").on("value", function(snapshot) {
   // Loops through the matching issues
   snapshot.forEach(function(child) { 
      console.log(child.key); 
   });
});