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

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

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 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