【问题标题】:basic firebase rules and search基本的 Firebase 规则和搜索
【发布时间】:2017-11-06 16:01:35
【问题描述】:

您好,我正在尝试为学校制作一个简单的食谱反应本机应用程序。

我对原生和 noSQL 反应不熟悉。那么我如何查询对我的firebase做出本机反应呢?

我想做的是搜索特定产品并获取包含该产品的所有食谱。接下来我想做的就是能够 添加另一种产品并找到同时具有这两种产品的配方,依此类推。

我的 firebase 有这个设置:

enter image description here

【问题讨论】:

    标签: firebase react-native


    【解决方案1】:

    注意:对于更复杂的查询,我建议使用cloud functions

    关于您的问题:使用这样的数据结构,使用 firebase sdk 提供的查询是不可能实现您想要的。问题是你的食谱有ingredient1: 5505ingredient2: 4404 ...将它们更改为5505: true4404: true。然后像这样使用sdk:

    const getRecipesForProduct = async (productName) => {
        const product = await firebase.database().ref('products').orderByChild("name").equalTo(productName).once('value').then(snap => {...snap.val(), uid: snap.key()})
        const recipes = await firebase.database().ref('recipe').orderByChild(product.uid).equalTo(true).once('value').then(snap => snap.val())
        // do something with recipes
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-27
      • 2021-01-21
      • 2014-12-07
      • 1970-01-01
      • 1970-01-01
      • 2018-07-03
      相关资源
      最近更新 更多