【问题标题】:Query specific uid in Firebase using Angular2+使用 Angular2+ 在 Firebase 中查询特定的 uid
【发布时间】:2021-11-20 20:19:56
【问题描述】:

我真的很困惑如何通过 uid 查询 firebase 中的单个记录。 我有一个用户 ID,想查询下表。我正在使用以下代码。 但是,它会返回两条记录,而不仅仅是“this.selectedId”。是否有 1) 只返回被查询记录的方法 2) 保留键而不是索引 0、1、2、3 等的数组...

使用的代码

const itemsRef = this.afs.collection<any>(`/profiles/`);
itemsRef.valueChanges(this.selectedId).subscribe(
    x => {
      console.log("Value change", x);
    }
);

图片

返回结果

【问题讨论】:

  • 请不要包含结果的屏幕截图。将文本复制到您的答案中。

标签: javascript angular firebase google-cloud-firestore angularfire2


【解决方案1】:

valueChanges 方法不带任何参数。如果你想monitor a single document

const itemRef = this.afs.doc<any>(`/profiles/`+this.selectedId);
itemRef.valueChanges()...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-10
    • 1970-01-01
    • 2018-11-15
    • 2017-09-16
    • 2017-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多