1
this.afs.collection<User>(`users`).valueChanges()
    .map(domains => {
        return this.convertToArray(domains).filter(domain => {
          return domain;
        });
    });

Domain returns:

{creationDate:1516798886902
displayName:"mohamedabo8414"
domain:"@mohamedabo8414"
followersCount:0
followingCount:0}

I want to get uid for this user. How can I do it?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Mohamed Abo Elmagd
  • 1,077
  • 11
  • 17

2 Answers2

2

.valueChanges() doesn't emit the keys with it. use .snapshotChanges() instead. Try

this.afs.collection<User>(`users`).snapshotChanges().map(actions=>{
    return actions.map(b=>{
      const data = b.payload.doc.data();
      const id = b.payload.doc.id;
      return {uid:id,...data}
    })
}).map(domains => {
    return this.convertToArray(domains).filter(domain => {
      return domain;
    });
});
Hareesh
  • 6,770
  • 4
  • 33
  • 60
0

Based on your comment

I named domain object with uid like this "VEtdoqabg4bkanB6Ky9CI3dvzOu1": { creationDate:1516798886902 displayName:"mohamedabo8414" domain:"@mohamedabo8414" followersCount:0 followingCount:0}

If you want to fetch the uid VEtdoqabg4bkanB6Ky9CI3dvzOu1 then according to the official documentation, in your case domain.id() should get you the above uid.

Dhara Bhavsar
  • 345
  • 4
  • 11