0

I am building a React app with a Firebase back end and Firebase Cloud Functions. I have a collection called 'users' and in it users are stored with their uid and data which include Name and phone number. Each user has a unique phone number. The user data looks like this:

{
    uid: i8uCaO5yDYT5aICpFgxPJYRLzor1,
    data: {
        first_name: 'Name',
        last_name: 'Alsoname',
        id_number: '123242133'
    }
}

I would like to get back a user data object if the ID number matches the parameter I pass. I try doing it like this:

    const userObject = admin.firestore().collection('users')
    .where('id_number', '==', '123242133').get();

I am stuck on how to get the uid of this user and the other data that is inside of it. Please help. Thanks.

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
David
  • 473
  • 1
  • 4
  • 14
  • Have you tried `where('data.id_number', '==', '123242133')`? – Dharmaraj Jan 04 '23 at 06:50
  • The query works, the issue I face is with converting the [{}] array I get back to an object {} with an ID – David Jan 04 '23 at 06:52
  • Like `const result = userObject.docs.map(d => ({ id: d.id, ...d.data() }))`? The `userObject` is a [QuerySnapshot](https://firebase.google.com/docs/reference/js/firestore_.querysnapshot) – Dharmaraj Jan 04 '23 at 06:53
  • I rollbacked the changes as it was different than original issue mentioned in the question before being closed. – Dharmaraj Jan 04 '23 at 06:55

0 Answers0