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

327
Visualizações
how to get users from firestore database with Like query

this function work fine with equal string but i need to search a substring: if i write "h" and the string is "hello" i need to return that

async getUsers(searchUser) {
            
            return firestore().collection('Users').where(searchUser).where('firstName', '==', searchUser)
            .limit(20).get().then(snapshot => {
                snapshot.docs.forEach(doc => {
                    const usersData = { ...doc.data(), id: doc.id };
                    return usersData
                });
            })
        }
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I can give you answer! In that case, you must use a dedicated third-party search service. These services provide advanced indexing and search capabilities far beyond what any simple database query can offer. Please use "Algolia" and at that time your code according to your expectations must be like this.

const client = algoliasearch('YourApplicationID', 'YourSearchOnlyAPIKey');
const index = client.initIndex('firstName');
index.search(searchUser, {
  attributesToRetrieve: ['firstname', 'lastname'/*, .. etc the fields you need*/],
  hitsPerPage: 20 /* the page Size */,
}).then(({ hits }) => {
  console.log(hits); // the results you want
});

Just try it. Helpful for you? If it's successful, I would be happy. If you have a question please contact "Nykolai.B0411@outlook.com". I will help you. Thanks.

about 4 years ago · Juan Pablo Isaza Relatório

0

When you register a new user to your app you can store their username/firstname in firestore as an array that includes the possible ways you would search for a user (look at the attached image). You can do that by splitting the name string.

search options array in user doc in firestore

then you can query the users collection by searching in that array using arrayContains like this:

await usersCollection
        .where('searchOptions', arrayContains: searchText)
        .get()
        .then((value) =>
            value.docs.map((doc) => User.fromSnapShot(doc)).toList());

If you need more capabilities than that you might need to use a 3rd party service. but this solution should be sufficient for your case.

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