且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在所有子项中查询具有特定值的属性的 firebase

更新时间:2023-01-17 18:36:24

Firebase 中没有 WHERE 子句.查看此主题,了解一些很棒的结构按多个字段搜索的提示,此主题关于数据库样式查询,此博客 关于查询,以及 文档.

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.