Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
Best way to query for team id from team name and then query for all users with that team id in firestore?

I have a collections of users where each document ID is the uid and the documents have 2 fields: user_name and team_id. I have another collection of teams where each document ID is randomly generated and the documents have 2 fields: team_name and team_id (the randomly generated id).

I am using react router and useParams to a team name to a component. I would like to query the team collection to see which document in there has team_name equal to the team name that is passed. Then I would like to get the team_id from the document that has that team name and use it to query the user collection for which users have that team_id.

I know if I can get the team_id then I can do something like:

const queryRef = query(
  collection(db, 'users'),
  where('team_id', '==', team.id)
);
const [users] = useCollectionOnce(queryRef);

and then inside my return do something like:

{videos.docs.map((user) => {
  const data = user.data();
  const userName = data.user_name;
  return (
    // display userNames in some way
  );
})}

I was wondering what the best way to get the team_id value from the team_name value or if there are any other better ways to get the list of users.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

What you are currently doing is pretty straightforward way to handle this situation. First fetching team ID by team name and then querying users with that team ID.

One way you can remove first query is to use team ID itself in the URL so you can directly query users but then the URL won't be much user friendly. Additionally you can try to format your URL like how StackOverflow does. It has question ID (which is required) but also has title of the question so users can get some context of URL. The title however isn't necessary and URL works as long as the question ID is present.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!