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

129
Visualizações
how to find all documents with only looking at first letter of the values in mongoose

i want to find all documents by its first letter.

the case is when i query in mysql then i could do WHERE Stores LIKE 'a%'

the result would be all data with the first letter a.

the question are :

  • How to make the same query using mongoose?
  • how about case-sensitive eg: (a,A). it would be the same query or not?
  • is it necessary to create lowercase_field for this case ?
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

There is a $regex operator for that purpose, the query will look like:

Model.find({"name": {$regex: /^a/, $options: 'i'}}).exec(callback);

and it could be simplified to:

Model.find({"name": /^a/i}}).exec(callback);

In case you need to pass a variable in the query:

var char = 'a';
Model.find({"name": {$regex: '^' + char, $options: 'i'}}).exec(callback);
over 4 years ago · Santiago Trujillo 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