Firebase - 获取包含的所有数据 [英] Firebase - Get All Data That Contains

查看:26
本文介绍了Firebase - 获取包含的所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 firebase 模型,其中每个对象都如下所示:

I have a firebase model where each object looks like this:

done: boolean
|
tags: array
|
text: string

每个对象的 tag 数组可以包含任意数量的字符串.

Each object's tag array can contain any number of strings.

如何获取所有具有匹配标签的对象?例如,查找 tag 包含email"的所有对象.

How do I obtain all objects with a matching tag? For example, find all objects where the tag contains "email".

推荐答案

随着 API 的不断扩展,许多更常见的搜索方案,例如按属性搜索(因为您的标签数组将包含)将被纳入 Firebase.

Many of the more common search scenarios, such as searching by attribute (as your tag array would contain) will be baked into Firebase as the API continues to expand.

与此同时,您当然可以自己种植.根据您的问题,一种方法是简单地使用匹配的记录列表索引"标签列表:

In the mean time, it's certainly possible to grow your own. One approach, based on your question, would be to simply "index" the list of tags with a list of records that match:

/tags/$tag/record_ids...

然后要搜索包含给定标签的记录,您只需对标签列表进行快速查询:

Then to search for records containing a given tag, you just do a quick query against the tags list:

new Firebase('URL/tags/'+tagName).once('value', function(snap) {
    var listOfRecordIds = snap.val();
});

这是一个非常常见的 NoSQL 口头禅——在初始写入中投入更多精力,以便以后读取容易.这也是一种常见的非规范化 方法(和一个大多数 SQL 数据库在内部使用,在更复杂的层面上).

This is a pretty common NoSQL mantra--put more effort into the initial write to make reads easy later. It's also a common denormalization approach (and one most SQL database use internally, on a much more sophisticated level).

另请参阅 Frank 提到的帖子,因为它可以帮助您扩展到更高级的搜索主题.

Also see the post Frank mentioned as that will help you expand into more advanced search topics.

这篇关于Firebase - 获取包含的所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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