如何在所有的孩子中查询具有特定价值的财产 [英] How to query firebase for property with specific value inside all children

查看:120
本文介绍了如何在所有的孩子中查询具有特定价值的财产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个数据结构,其中todos按照路径/ todos / uid /

I have this data structure, where todos are organized to follow path /todos/uid/

{
  "metausers" : {
    "simplelogin:1" : {
      "displayName" : "John Doe",
      "provider" : "password",
      "provider_id" : "1"
    },
    "simplelogin:2" : {
      "displayName" : "GI Jane",
      "provider" : "password",
      "provider_id" : "2"
    }
  },
  "todos" : {
    "simplelogin:1" : {
      "-JUAfv4_-ZUlH7JqM4WZ" : {
        "completed" : false,
        "done" : false,
        "group" : false,
        "private" : false,
        "subject" : "First"
      },
      "-JUAfveXP_sqqX32jCJS" : {
        "completed" : false,
        "done" : false,
        "group" : false,
        "private" : true,
        "subject" : "Second"
      },
      "-JUAfwXnMo6P53Qz6Fd2" : {
        "completed" : false,
        "done" : false,
        "group" : false,
        "private" : false,
        "subject" : "Third"
      }
    },
    "simplelogin:2" : {
      "-JUAg9rVemiNQykfvvHs" : {
        "completed" : false,
        "done" : false,
        "group" : false,
        "private" : false,
        "subject" : "Q first"
      },
      "-JUAgAmgPwZLPr2iH1Ho" : {
        "completed" : false,
        "done" : false,
        "group" : false,
        "private" : false,
        "subject" : "Q second"
      },
      "-JUAgBfF8f7V5R5-XgrY" : {
        "completed" : false,
        "done" : false,
        "group" : false,
        "private" : true,
        "subject" : "Q third"
      }
    }
  }
}

,我想查询todos获取所有记录与 private:true 。这可能使用firebase(angularfire),我应该怎么做?或者我应该反规范化一点,并安排路径/私人,以避免走下来的todos?

and i would like to query todos to get all records with private:true. Is this possible using firebase (angularfire) and how should i do it ? Or should i denormalize a bit more and arrange path /private to avoid of walking down todos ?

推荐答案

Firebase中的$ c> WHERE 子句。查看这个线程的一些很好的结构有关数据库风格查询的这个线程的提示,关于查询的这个博客,以及 docs

There are no WHERE clauses in Firebase. Check out this thread for some great structural tips on searching by multiple fields, this thread on database style queries, this blog on queries, and the docs.

你的第一个方法应该是分割数据如何被读回。如下所示:

Your first approach should be to segment data how it will be read back. Something like the following:

/todos/public
/todos/private
/todos/completed

您也可以利用优先级,如文档中所述。然后根据优先级获取项目。

You can also utilize priorities as explained in the docs. Then fetch items based on priority.

如果列表小于一千,这应该是数据正确分区,您可能只需抓取待办事项列表在客户端过滤它 - 这是一个很好的选择像这样的短集合,特别是使用像Angular这样的一个很好的绑定库。

If the list is less than a thousand, which it should be if data is properly partitioned, you can probably just grab the todo list and filter it at the client as well--a great option for short collections like this, particularly when working with a great binding lib like Angular.

这篇关于如何在所有的孩子中查询具有特定价值的财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆