在儿童的小孩的Firebase中查询 [英] Querying in Firebase by child of child
问题描述
-KBP27k4iOTT2m873xSE
类别
地理:真正的
大洋洲:真正的
correctanswer:Yaren(事实上)
语言:英语
问题:瑙鲁
questiontype:
wronganswer1:Majuro
wronganswer2:Mata-Utu
wronganswer3:Suva
我试图按类别查找对象,因此我想要所有具有Oceania类别的对象。
我正在使用Swift,我似乎无法理解如何查询数据。
我的查询现在看起来像这样:
ref.queryEqualToValue(,childKey:categories)。queryOrderedByChild(Oceania)
其中 ref
是对特定路径中的Firebase的引用。
$ b
然而无论我试过我k eep获取返回的所有数据,而不是只有大洋洲类别的对象。
我的数据结构如下: 正如您在对象示例中所看到的,一个问题可以添加多个类别,所以从我所了解的情况来看,最好有一个对类别的引用我可以改变我的结构为 通过使用 我想知道这是要走还是?我应该重组我的数据吗?该应用程序尚未投入生产,因此可以完全重构数据,而不会造成更大的后果,除非我必须重写代码,将数据推送到Firebase。 让我知道,如果所有这一切都没有道理和遗憾的文字墙: - ) 解决方案 baseurl / questions / $ c
baseurl / questions / oceania / uniqueids /
,但是然后我会得到多个涉及相同数据的条目,但具有不同的 uniqueid
,因为问题将出现在类别 oceania
和 geography
。
baseurl / questions / oceania / code>和
和 baseurl / questions / geography
我也可以在 unique ids
>大洋洲 geography
指向内的特定
代替,但这意味着我必须跟踪大量的引用。做一个关系表可以这么说。唯一ID
>的BaseURL /问题/ uniquei ds
我认为这应该工作:
$ b $ pre $ ref.queryOrderedByChild(categories / Oceania)。queryEqualToValue(true)
I have a structure of objects in Firebase looking like this:
-KBP27k4iOTT2m873xSE
categories
Geography: true
Oceania: true
correctanswer: "Yaren (de facto)"
languages: "English"
question: "Nauru"
questiontype: "Text"
wronganswer1: "Majuro"
wronganswer2: "Mata-Utu"
wronganswer3: "Suva"
I'm trying to find objects by categories, so for instance I want all objects which has the category set to "Oceania".
I'm using Swift and I can't really seem to grasp the concept of how to query the data.
My query right now looks like this:
ref.queryEqualToValue("", childKey: "categories").queryOrderedByChild("Oceania")
Where ref
is the reference to Firebase in that specific path.
However whatever I've tried I keep getting ALL data returned instead of the objects with category Oceania only.
My data is structured like this: baseurl/questions/
As you can see in the object example one question can have multiple categories added, so from what I've understood it's best to have a reference to the categories inside your objects.
I could change my structure to baseurl/questions/oceania/uniqueids/
, but then I would get multiple entries covering the same data, but with different uniqueid
, because the question would be present under both the categories oceania
and geography
.
By using the structure baseurl/questions/oceania/
and baseurl/questions/geography
I could also just add unique ids
under oceania
and geography
that points to a specific unique id
inside baseurl/questions/uniqueids
instead, but that would mean I'd have to keep track of a lot of references. Making a relations table so to speak.
I wonder if that's the way to go or? Should I restructure my data? The app isn't in production yet, so it's possible to restructure the data completely with no bigger consequences, other than I'd have to rewrite my code, that pushes data to Firebase.
Let me know, if all of this doesn't make sense and sorry for the wall of text :-)
I think this should work:
ref.queryOrderedByChild("categories/Oceania").queryEqualToValue(true)
这篇关于在儿童的小孩的Firebase中查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!