简体   繁体   中英

Query specific uid in Firebase using Angular2+

Im really confused on how to query a single record in firebase by the uid. I have a user id and want to query the following table. I am using the following code. However, it is returning both the records instead of just the 'this.selectedId' one. Is there 1) A way to just return the record being queried 2) keep the key instead of array of index 0, 1, 2, 3 etc...

Code used

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

Image

这是结构。

Returned result在此处输入图像描述

The valueChanges method doesn't take any parameters. If you want to monitor a single document

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM