如何通过查询文档ID从FireStore获取收集信息?

时间:2018-10-20 04:50:44

标签: angular google-cloud-firestore

我正在尝试在Angular 6项目中学习Firestore的基础知识,并且有以下代码片段。

public usersCollection: AngularFirestoreCollection<FSdata.Users>;
public users: Observable<FSdata.Users[]>;    

searchByUsername(){
      console.log(this.usernamestring);
      this.usersCollection = this.afs.collection<FSdata.Users>('Users', ref => 
           ref.where('username', '==', this.usernamestring)); //Users is the 
           name of the collection found in FireStore
      this.users = this.usersCollection.snapshotChanges().pipe(
           map(actions => {
           return actions.map(a => {
              const data = a.payload.doc.data() as FSdata.Users;
              const id = a.payload.doc.id;
              return { id, ...data };
           });
      })
  );
}

此功能非常适合我的表单,然后该表单将返回所有匹配的用户名(以及相应的信息),如下所示:

enter image description here

但是,我试图通过文档ID找出如何执行相同的操作。在图像中,文档ID在每个点都以粗体显示。我不知道如何修改我的函数以通过文档ID进行查询。

任何帮助将不胜感激!

0 个答案:

没有答案