Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda