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

266
Visualizações
How to lowercase field data in MongoDB find()

In my database collection I have two Objects.

[
  {"_id" : 1, name: "notLowercased"},
  {"_id" : 2, name: "lowercased"},
]

I'm using find and $regex to find name that includes some string.

data = await CatalogModel.find({name: {$regex : searcher.toString().toLowerCase()}})

For example my input string is "lowercased".

In result I'm getting an array

[
  {"_id" : 2, name: "lowercased"},
]

But I want to get in result this:

[
  {"_id" : 1, name: "notLowercased"},
  {"_id" : 2, name: "lowercased"},
]

I'm understand that it's happening becase name "notLowercased" not lowercased.

How to lowercase name fields in this request?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can add $options parameter like this: $options: "i".

As explained into docs:

i: Case insensitivity to match upper and lower cases. For an example, see Perform Case-Insensitive Regular Expression Match.

Even you can avoid toLowerCase()

data = await CatalogModel.find({name: {$regex : searcher.toString(), "$options": "i" }})

Example here and without toLowerCase() here

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