【问题标题】:Correct structure and query for Realtime Firebase Database实时 Firebase 数据库的正确结构和查询
【发布时间】:2018-04-06 17:46:09
【问题描述】:

如何在 Firebase 中构建我的数据库以搜索食谱?每个食谱都有一些成分。我需要搜索食谱。如果查询包含多个匹配的成分,我需要输出一个包含匹配值的配方。

这是我现在的数据库结构:

{
  "Recepts" : [ {
    "Ingridients" : [ "Carrot", "Sugar" ],
    "Name" : "Carrot Salad"
  }, {
    "Ingridients" : [ "Orange", "Milk" ],
    "Name" : "Orange Milk"
  } ]
}

如果正确,我该如何查询我的数据库?

【问题讨论】:

    标签: java database firebase firebase-realtime-database


    【解决方案1】:

    It is a best practice 避免使用数组并将数据列表保存为地图。

    要搜索具有某种成分的食谱,请 you could use orderByChildequalTo 您要查找的成分。

    数据结构是

    {
        "Recipes" : {
            "CarrotSalad": {
                "Ingredients" : {
                    "Carrot": true,
                    "Sugar": true
                },
                "Name" : "Carrot Salad"
            }, 
        ....
        }
    }
    

    【讨论】:

    • 如果对你来说不难的话,你能举一个这样的查询的例子吗?
    • @ВладЮлин 我不知道您使用的语言,无论如何,按照我帖子中的第二个链接,您可以看到多种语言的官方示例。如果您认为有用,请不要忘记投票并接受答案,请务必让 stackoverflow 继续正常工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-24
    • 2021-10-01
    • 1970-01-01
    • 2019-07-31
    • 1970-01-01
    • 1970-01-01
    • 2015-05-31
    相关资源
    最近更新 更多