【问题标题】:Make a `where` in Ionic with Firebase 3使用 Firebase 3 在 Ionic 中创建“位置”
【发布时间】:2017-09-06 16:15:13
【问题描述】:

我在 Firebase 中有我的数据库,但我想做一个 WHERE,作为登录名(即,如果我输入用户和密码,它会给我带来用户的相应数据)。

这是我在 firebase 中的数据库:

一个例子:

当我将电子邮件和电话发送到 tb01_usuario 时,给我带来相应的数据:

目前我只用类似于外地电话的ID来做,但我需要用每条记录内的两个字段来做,希望他们理解我

verifica_usuario(telefono: string,email : email ) {

    email = email;
    telefono = telefono;

    let promesa = new Promise((resolve, reject) => {
      //this.items = afDB.list('/cuisines');
      this.af.list('/tb01_usuario/' + telefono + email )
        .subscribe(data => {
          if (data.length === 0) {
            //clave no es correcta
            resolve(false);
          } else {
            //clave correcta
            this.telefono = telefono;
            this.guardar_storage();
            resolve(true);
          }
        });
    })
      .catch(error => console.log("ERROR en promesa Service: " + JSON.stringify(error)));

    return promesa;
  }

【问题讨论】:

  • 这个问题很不清楚——你是在问如何在 Firebase 中基于两个子节点执行查询;姓名和电话?即其中 name = 'some name' and phone = 'some电话'?

标签: firebase ionic-framework firebase-realtime-database ionic3


【解决方案1】:

您不能直接在 Firebase 中执行此操作。

根据Firebase docs

实时数据库 API 旨在仅允许可以快速执行的操作。

您应该structure your data 以您可以轻松获取所需内容的方式。

【讨论】:

  • 使用 FireBase 在 Ionic 3 中创建 where
  • 告诉 OP“阅读文档”真的不是一个答案。如何通过代码和 Firebase 结构示例为问题提供答案(解决方案)?
【解决方案2】:

您可能想要使用冗余节点(类似于 MarianoCordoba 提到的),它以一种更容易访问所需内容的方式复制数据,或者 indexOn (documentation) 和 @987654324 @ (documentation)。请注意,您还可以使用 orderByKey()orderByValue(),它们允许您过滤/排序数据(这就是我假设您在 Firebase 中使用 WHERE 的意思)。

【讨论】:

    猜你喜欢
    • 2020-10-15
    • 2018-09-29
    • 2017-01-04
    • 2018-03-21
    • 2019-01-28
    • 2018-02-13
    • 2022-08-19
    • 2018-02-19
    • 1970-01-01
    相关资源
    最近更新 更多