Firestore Searching

42 Views Asked by At

I have a 'Users' collection containing documents named with UIDs. And each UID document has two collections, 'Documents' and 'UserDetails'. 'UserDetails' has a document called 'Basic' which contains a field called 'referralCode'. Now whenever a new user enters a refferal code, then I want to search my firestore database for the UID matching with that particular code. How can I acheive this?

Following are the pictures of the database for more clarity.

Picture1

Picture2

1

There are 1 best solutions below

2
Frank van Puffelen On BEST ANSWER

If you want to search across multiple (sub) collections of the same name, you can use a collection group query.

Once you get a result in there, you can from the DocumentSnapshot navigate up to its reference and from there find the parent property to find the exact collection path the result is in.