Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

322
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda