Firebase实时数据库EqualTo索引规则Xamarin表单

时间:2020-11-05 02:03:43

标签: firebase firebase-realtime-database xamarin.forms firebase-security

我正在Visual Studio上执行Xamarin Forms多平台应用程序。 我使用Firebase Realtime Database,并创建了这样的嵌套表

enter image description here

我需要创建一个列表视图,在其中可以查看用户阅读的每本书(按类型过滤)。

return (await firebase
              .Child("Utenti")
              .Child(ID)
              .Child("Books")
              .OrderBy("Genere")
              .EqualTo("Gialli")
              .OnceAsync<Utente>()).Select(item => new Utente
              {

              }).ToList();

问题是我必须更新实时数据库规则并添加indexOn Genere才能使用EqualTo。但是ID总是会更改,因为它是用户的UID。

我尝试过

"Utenti": {
".indexOn": ["Genere"] }

但是应用程序崩溃了,并要求我使用整个根目录。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

在特定位置定义索引(及其查询),然后对每个子节点下特定路径处的值进行索引(并排序)。您的<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table class="table text-center table-borderless"> <thead> <tr> <th class="table-danger t" scope="col">Paramètres disponibles</th> </tr> </thead> <tbody class="bodyGauche"> <tr> <td id=annees> <button class="buttonParam" onclick="changeTable(this)">annees</button> </td> </tr> <tr> <td id=producteurs> <button class="buttonParam" onclick="changeTable(this)">producteurs</button> </td> </tr> <tr> <td id=depots> <button class="buttonParam" onclick="changeTable(this)">depots</button> </td> </tr> <tr> <td id=commandes> <button class="buttonParam" onclick="changeTable(this)">commandes</button> </td> </tr> <tr> <td id=clients> <button class="buttonParam" onclick="changeTable(this)">clients</button> </td> </tr> </tbody> </table>的子节点没有Utenti属性,因此索引将为空。

要在JSON屏幕截图中为属性建立索引,您需要一个类似这样的索引:

Genere

使用此定义,"Utenti": { ".indexOn": ["Books/codice0/Genere"] } 的每个子节点将根据其Utenti属性的值在索引中。这也立即意味着您只能拥有一个Books/codice0/Genere值,因此您无法跨多本书进行搜索。

如果要搜索所有书籍中的所有Utenti,则需要创建数据结构中所有书籍的平面列表。然后,您可以将Utenti的密钥作为属性存储在书中,从而将书与Utenti关联起来。

另请参阅: